diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-12-10 11:54:30 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-12-10 11:54:30 +0300 |
commit | aec35e582d3c5a51d1ae1e7c2e107ebbedca1955 (patch) | |
tree | 45a37dc024226449e13f9e5b9d96fba87c6b1ae0 /app/src/main/java/it/niedermann | |
parent | f29eed9db4c0906fa7887e446cf0325718ef6827 (diff) |
Minor code clean ups
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main/java/it/niedermann')
9 files changed, 32 insertions, 27 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java index 3ded31bb7..1ba1415b2 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java @@ -1,6 +1,7 @@ package it.niedermann.nextcloud.deck.ui; import android.annotation.SuppressLint; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.database.sqlite.SQLiteConstraintException; @@ -251,4 +252,8 @@ public class ImportAccountActivity extends AppCompatActivity { editor.putBoolean(prefKeyWifiOnly, originalWifiOnlyValue); editor.apply(); } + + public static Intent createIntent(@NonNull Context context) { + return new Intent(context, ImportAccountActivity.class); + } }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java index d7e726a7d..06fa3186b 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java @@ -132,9 +132,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener private FilterViewModel filterViewModel; private PickStackViewModel pickStackViewModel; - protected static final int ACTIVITY_ABOUT = 1; protected static final int ACTIVITY_SETTINGS = 2; - public static final int ACTIVITY_MANAGE_ACCOUNTS = 4; @NonNull protected List<Account> accountsList = new ArrayList<>(); @@ -158,8 +156,6 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener private boolean firstAccountAdded = false; private ConnectivityManager.NetworkCallback networkCallback; - private String accountAlreadyAdded; - private String urlFragmentUpdateDeck; private String addList; private String addBoard; @Nullable @@ -186,8 +182,6 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener addList = getString(R.string.add_list); addBoard = getString(R.string.add_board); - accountAlreadyAdded = getString(R.string.account_already_added); - urlFragmentUpdateDeck = getString(R.string.url_fragment_update_deck); setSupportActionBar(binding.toolbar); @@ -202,7 +196,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener if (hasAccounts) { return mainViewModel.readAccounts(); } else { - startActivityForResult(new Intent(this, ImportAccountActivity.class), ImportAccountActivity.REQUEST_CODE_IMPORT_ACCOUNT); + startActivityForResult(ImportAccountActivity.createIntent(this), ImportAccountActivity.REQUEST_CODE_IMPORT_ACCOUNT); return null; } }).observe(this, (List<Account> accounts) -> { @@ -300,7 +294,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener Glide .with(binding.accountSwitcher.getContext()) - .load(currentAccount.getAvatarUrl(64)) + .load(currentAccount.getAvatarUrl(binding.accountSwitcher.getWidth())) .placeholder(R.drawable.ic_baseline_account_circle_24) .error(R.drawable.ic_baseline_account_circle_24) .apply(RequestOptions.circleCropTransform()) @@ -314,7 +308,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener binding.infoBoxVersionNotSupportedText.setText(getString(R.string.info_box_version_not_supported, mainViewModel.getCurrentAccount().getServerDeckVersion(), Version.minimumSupported(this).getOriginalVersion())); binding.infoBoxVersionNotSupportedText.setOnClickListener((v) -> { Intent openURL = new Intent(Intent.ACTION_VIEW); - openURL.setData(Uri.parse(mainViewModel.getCurrentAccount().getUrl() + urlFragmentUpdateDeck)); + openURL.setData(Uri.parse(mainViewModel.getCurrentAccount().getUrl() + getString(R.string.url_fragment_update_deck))); startActivity(openURL); }); binding.infoBoxVersionNotSupported.setVisibility(View.VISIBLE); @@ -648,10 +642,10 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case MENU_ID_ABOUT: - startActivityForResult(AboutActivity.createIntent(this, mainViewModel.getCurrentAccount()), MainActivity.ACTIVITY_ABOUT); + startActivity(AboutActivity.createIntent(this, mainViewModel.getCurrentAccount())); break; case MENU_ID_SETTINGS: - startActivityForResult(new Intent(this, SettingsActivity.class), MainActivity.ACTIVITY_SETTINGS); + startActivityForResult(SettingsActivity.createIntent(this), MainActivity.ACTIVITY_SETTINGS); break; case MENU_ID_ADD_BOARD: EditBoardDialogFragment.newInstance().show(getSupportFragmentManager(), addBoard); @@ -818,7 +812,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener .setNegativeButton(R.string.simple_discard, null) .setPositiveButton(R.string.simple_update, (dialog, whichButton) -> { final Intent openURL = new Intent(Intent.ACTION_VIEW); - openURL.setData(Uri.parse(createdAccount.getUrl() + urlFragmentUpdateDeck)); + openURL.setData(Uri.parse(createdAccount.getUrl() + getString(R.string.url_fragment_update_deck))); startActivity(openURL); finish(); }).show()); @@ -855,7 +849,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener final Throwable error = accountLiveData.getError(); if (error instanceof SQLiteConstraintException) { DeckLog.warn("Account already added"); - BrandedSnackbar.make(binding.coordinatorLayout, accountAlreadyAdded, Snackbar.LENGTH_LONG).show(); + BrandedSnackbar.make(binding.coordinatorLayout, R.string.account_already_added, Snackbar.LENGTH_LONG).show(); } else { ExceptionDialogFragment.newInstance(error, createdAccount).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PickStackActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PickStackActivity.java index 2339a8783..5103cf3c1 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PickStackActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PickStackActivity.java @@ -1,6 +1,5 @@ package it.niedermann.nextcloud.deck.ui; -import android.content.Intent; import android.content.res.ColorStateList; import android.graphics.Color; import android.os.Bundle; @@ -64,7 +63,7 @@ public abstract class PickStackActivity extends AppCompatActivity implements Bra if (hasAccounts) { return viewModel.readAccounts(); } else { - startActivityForResult(new Intent(this, ImportAccountActivity.class), ImportAccountActivity.REQUEST_CODE_IMPORT_ACCOUNT); + startActivityForResult(ImportAccountActivity.createIntent(this), ImportAccountActivity.REQUEST_CODE_IMPORT_ACCOUNT); return null; } }).observe(this, (List<Account> accounts) -> { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/about/AboutActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/about/AboutActivity.java index bf3734b72..d931d5c92 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/about/AboutActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/about/AboutActivity.java @@ -42,8 +42,6 @@ public class AboutActivity extends BrandedActivity { setSupportActionBar(binding.toolbar); binding.viewPager.setAdapter(new TabsPagerAdapter(getSupportFragmentManager(), getLifecycle(), (Account) getIntent().getSerializableExtra(BUNDLE_KEY_ACCOUNT))); new TabLayoutMediator(binding.tabLayout, binding.viewPager, (tab, position) -> tab.setText(tabTitles[position])).attach(); - - setResult(RESULT_OK); } private static class TabsPagerAdapter extends FragmentStateAdapter { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher/AccountSwitcherDialog.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher/AccountSwitcherDialog.java index 744498c4a..8a70cf12d 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher/AccountSwitcherDialog.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher/AccountSwitcherDialog.java @@ -1,7 +1,6 @@ package it.niedermann.nextcloud.deck.ui.accountswitcher; import android.app.Dialog; -import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -26,7 +25,6 @@ import it.niedermann.nextcloud.deck.ui.branding.BrandedDialogFragment; import it.niedermann.nextcloud.deck.ui.manageaccounts.ManageAccountsActivity; import static it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.LiveDataHelper.observeOnce; -import static it.niedermann.nextcloud.deck.ui.MainActivity.ACTIVITY_MANAGE_ACCOUNTS; public class AccountSwitcherDialog extends BrandedDialogFragment { @@ -80,7 +78,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { }); binding.manageAccounts.setOnClickListener((v) -> { - requireActivity().startActivityForResult(new Intent(requireContext(), ManageAccountsActivity.class), ACTIVITY_MANAGE_ACCOUNTS); + requireActivity().startActivity(ManageAccountsActivity.createIntent(requireContext())); dismiss(); }); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/manageaccounts/ManageAccountsActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/manageaccounts/ManageAccountsActivity.java index 8aa45e39a..aec258d59 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/manageaccounts/ManageAccountsActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/manageaccounts/ManageAccountsActivity.java @@ -1,8 +1,11 @@ package it.niedermann.nextcloud.deck.ui.manageaccounts; +import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.util.Log; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.lifecycle.ViewModelProvider; @@ -51,7 +54,6 @@ public class ManageAccountsActivity extends AppCompatActivity { viewModel.readAccounts().observe(this, (localAccounts -> { if (localAccounts.size() == 0) { Log.i(TAG, "No accounts, finishing " + ManageAccountsActivity.class.getSimpleName()); - setResult(AppCompatActivity.RESULT_FIRST_USER); finish(); } else { adapter.setAccounts(localAccounts); @@ -64,4 +66,8 @@ public class ManageAccountsActivity extends AppCompatActivity { public void onBackPressed() { onSupportNavigateUp(); } + + public static Intent createIntent(@NonNull Context context) { + return new Intent(context, ManageAccountsActivity.class); + } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/pickstack/PickStackFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/pickstack/PickStackFragment.java index d65971cf4..6408f6b64 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/pickstack/PickStackFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/pickstack/PickStackFragment.java @@ -1,7 +1,6 @@ package it.niedermann.nextcloud.deck.ui.pickstack; import android.content.Context; -import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -142,7 +141,7 @@ public class PickStackFragment extends Fragment { if (hasAccounts) { return viewModel.readAccounts(); } else { - startActivityForResult(new Intent(requireActivity(), ImportAccountActivity.class), ImportAccountActivity.REQUEST_CODE_IMPORT_ACCOUNT); + startActivityForResult(ImportAccountActivity.createIntent(requireContext()), ImportAccountActivity.REQUEST_CODE_IMPORT_ACCOUNT); return null; } }).observe(getViewLifecycleOwner(), (List<Account> accounts) -> { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/preparecreate/AccountAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/preparecreate/AccountAdapter.java index f537c9fb4..9534b51b4 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/preparecreate/AccountAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/preparecreate/AccountAdapter.java @@ -50,7 +50,7 @@ public class AccountAdapter extends AbstractAdapter<Account> { } Glide.with(getContext()) - .load(new SingleSignOnUrl(item.getName(), item.getAvatarUrl(DimensionUtil.INSTANCE.dpToPx(binding.avatar.getContext(), R.dimen.icon_size_details)))) + .load(new SingleSignOnUrl(item.getName(), item.getAvatarUrl(DimensionUtil.INSTANCE.dpToPx(binding.avatar.getContext(), R.dimen.avatar_size)))) .placeholder(R.drawable.ic_baseline_account_circle_24) .error(R.drawable.ic_baseline_account_circle_24) .apply(RequestOptions.circleCropTransform()) diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsActivity.java index 6f5a9a7e8..6440ba971 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsActivity.java @@ -1,7 +1,10 @@ package it.niedermann.nextcloud.deck.ui.settings; +import android.content.Context; +import android.content.Intent; import android.os.Bundle; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import it.niedermann.nextcloud.deck.R; @@ -11,14 +14,12 @@ import it.niedermann.nextcloud.deck.ui.exception.ExceptionHandler; public class SettingsActivity extends BrandedActivity { - private ActivitySettingsBinding binding; - @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); - binding = ActivitySettingsBinding.inflate(getLayoutInflater()); + final ActivitySettingsBinding binding = ActivitySettingsBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); setSupportActionBar(binding.toolbar); @@ -40,4 +41,9 @@ public class SettingsActivity extends BrandedActivity { public void applyBrand(int mainColor) { // Nothing to do... } + + @NonNull + public static Intent createIntent(@NonNull Context context) { + return new Intent(context, SettingsActivity.class); + } } |