Skip to content

Commit

Permalink
Merge pull request #2050 from moneymanagerex/sync
Browse files Browse the repository at this point in the history
Encryption: refine part of password input workflow
  • Loading branch information
wolfsolver authored Jan 3, 2025
2 parents ebb864f + c17f75c commit 3d17528
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
14 changes: 8 additions & 6 deletions app/src/main/java/com/money/manager/ex/home/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;

import com.google.common.io.Files;
import com.melnykov.fab.FloatingActionButton;
import com.money.manager.ex.Constants;
import com.money.manager.ex.MmexApplication;
Expand Down Expand Up @@ -86,10 +85,12 @@
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;

import javax.inject.Inject;
Expand Down Expand Up @@ -379,13 +380,14 @@ public void onResume() {
AppCompatActivity activity = (AppCompatActivity) getActivity();

// show title
activity.getSupportActionBar().setDisplayShowTitleEnabled(true);
Objects.requireNonNull(activity.getSupportActionBar()).setDisplayShowTitleEnabled(true);

// Show db name in toolbar.
String dbPath = new AppSettings(activity).getDatabaseSettings().getDatabasePath();
//String dbFileName = FilenameUtils.getBaseName(dbPath);
String dbFileName = Files.getNameWithoutExtension(dbPath);
activity.getSupportActionBar().setSubtitle(dbFileName);
if (dbPath != null && !dbPath.isEmpty()) {
activity.getSupportActionBar().setSubtitle(Paths.get(dbPath).getFileName().toString());
} else {
activity.getSupportActionBar().setSubtitle(R.string.path_database_not_exists);
}
}

// reload data.
Expand Down
38 changes: 26 additions & 12 deletions app/src/main/java/com/money/manager/ex/home/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,23 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
case RequestCodes.SELECT_DOCUMENT:
FileStorageHelper storageHelper = new FileStorageHelper(this);
DatabaseMetadata db = storageHelper.selectDatabase(data);
changeDatabase(db);
if (db.localPath.endsWith(".emb")) {
startActivity(new Intent(MainActivity.this, PasswordActivity.class));
} else {
MmexApplication.getApp().setPassword("");
changeDatabase(db);
}
break;

case RequestCodes.CREATE_DOCUMENT:
FileStorageHelper storageHelper2 = new FileStorageHelper(this);
DatabaseMetadata db2 = storageHelper2.createDatabase(data);
changeDatabase(db2);
if (db2.localPath.endsWith(".emb")) {
startActivity(new Intent(MainActivity.this, PasswordActivity.class));
} else {
MmexApplication.getApp().setPassword("");
changeDatabase(db2);
}
break;

case RequestCodes.PASSCODE:
isAuthenticated = false;
isInAuthentication = false;
Expand Down Expand Up @@ -574,12 +582,16 @@ public boolean onDrawerMenuAndOptionMenuSelected(DrawerMenuItem item) {
String key = item.getTag().toString();
DatabaseMetadata selectedDatabase = getDatabases().get(key);
if (selectedDatabase != null) {
// TODO request password 1/3
Intent intent = new Intent(MainActivity.this, PasswordActivity.class);
intent.putExtra(EXTRA_DATABASE_PATH, key);
startActivityForResult(intent, RequestCodes.REQUEST_PASSWORD);
// TODO request password 1/3 upon testing instead of extension
if (key.endsWith(".emb")) {
Intent intent = new Intent(MainActivity.this, PasswordActivity.class);
intent.putExtra(EXTRA_DATABASE_PATH, key);
startActivityForResult(intent, RequestCodes.REQUEST_PASSWORD);
} else {
MmexApplication.getApp().setPassword(""); // reset password
onOpenDatabaseClick(selectedDatabase);
}

// onOpenDatabaseClick(selectedDatabase);
return result;
}
}
Expand All @@ -593,12 +605,10 @@ public boolean onDrawerMenuAndOptionMenuSelected(DrawerMenuItem item) {
SyncManager sync = new SyncManager(this);
sync.triggerSynchronization();
} else if (itemId == R.id.menu_open_database) {
startActivity(new Intent(MainActivity.this, PasswordActivity.class));
FileStorageHelper helper = new FileStorageHelper(this);
helper.showStorageFilePicker();
// TODO request password 2/3
} else if (itemId == R.id.menu_create_database) {
startActivity(new Intent(MainActivity.this, PasswordActivity.class));
(new FileStorageHelper(this)).showCreateFilePicker();
// TODO request password 3/3
} else if (itemId == R.id.menu_account) {
Expand Down Expand Up @@ -1132,8 +1142,12 @@ private void handleIntent() {
Timber.d("Path intent file to open: %s", filePath);

// Open this database.
startActivity(new Intent(MainActivity.this, PasswordActivity.class));
DatabaseMetadata db = DatabaseMetadataFactory.getInstance(filePath);
if (db.localPath.endsWith(".emb")) {
startActivity(new Intent(MainActivity.this, PasswordActivity.class));
} else {
MmexApplication.getApp().setPassword("");
}
changeDatabase(db);
return;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ public class SelectDatabaseActivity extends MmxBaseFragmentActivity {
@Inject
Lazy<RecentDatabasesProvider> mDatabasesLazy;

private Toolbar mToolbar;
private Button createDatabaseButton;
private Button openDatabaseButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -58,9 +54,9 @@ protected void onCreate(Bundle savedInstanceState) {
MmexApplication.getApp().iocComponent.inject(this);

// Initialize views using findViewById()
mToolbar = findViewById(R.id.toolbar);
createDatabaseButton = findViewById(R.id.createDatabaseButton);
openDatabaseButton = findViewById(R.id.openDatabaseButton);
Toolbar mToolbar = findViewById(R.id.toolbar);
Button createDatabaseButton = findViewById(R.id.createDatabaseButton);
Button openDatabaseButton = findViewById(R.id.openDatabaseButton);

// Request external storage permissions for Android 6+.
MmxFileUtils fileUtils = new MmxFileUtils(this);
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/res/layout/activity_select_database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text="@string/intro_sync" />

<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--style="@style/RaisedButton">-->
<!--<com.money.manager.ex.view.RobotoButton-->
<!--android:id="@+id/setupSyncButton"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="@string/configure_sync" />-->
<!--</LinearLayout>-->

</LinearLayout>
</ScrollView>
</LinearLayout>

0 comments on commit 3d17528

Please sign in to comment.