diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e27e033e..d8249b7e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -130,9 +130,6 @@ - diff --git a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java index 5594c396..522746bd 100644 --- a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java @@ -289,7 +289,7 @@ public class MainActivity extends BaseActivity UserInfoCallback callback) { Call call = RetrofitClient.getApiInterface(this).userGetCurrent(); call.enqueue( - new Callback() { + new Callback<>() { @Override public void onResponse( @NonNull Call call, @NonNull Response response) { @@ -377,6 +377,12 @@ public class MainActivity extends BaseActivity @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { + if (fragment == null || !fragment.isAdded() || fragment.getView() == null) { + if (callback != null) { + callback.onUserAccountsLoaded(); + } + return; + } if (binding != null && userAccountsList != null && accountsAdapter != null) { @@ -394,6 +400,13 @@ public class MainActivity extends BaseActivity List userAccountsList, UserAccountsNavAdapter accountsAdapter, UserInfoCallback callback) { + if (!fragment.isAdded() || fragment.getView() == null) { + if (callback != null) { + callback.onUserAccountsLoaded(); + } + return; + } + UserAccountsApi userAccountsApi = BaseApi.getInstance(this, UserAccountsApi.class); assert userAccountsApi != null; userAccountsApi @@ -401,7 +414,10 @@ public class MainActivity extends BaseActivity .observe( fragment.getViewLifecycleOwner(), userAccounts -> { - if (!fragment.isAdded()) { + if (!fragment.isAdded() || fragment.getView() == null) { + if (callback != null) { + callback.onUserAccountsLoaded(); + } return; } if (userAccounts != null && !userAccounts.isEmpty()) { diff --git a/app/src/main/java/org/mian/gitnex/activities/SettingsCodeEditorActivity.java b/app/src/main/java/org/mian/gitnex/activities/SettingsCodeEditorActivity.java deleted file mode 100644 index 861dc9b5..00000000 --- a/app/src/main/java/org/mian/gitnex/activities/SettingsCodeEditorActivity.java +++ /dev/null @@ -1,162 +0,0 @@ -package org.mian.gitnex.activities; - -import android.os.Bundle; -import android.view.View; -import com.google.android.material.dialog.MaterialAlertDialogBuilder; -import org.mian.gitnex.R; -import org.mian.gitnex.databinding.ActivitySettingsCodeEditorBinding; -import org.mian.gitnex.fragments.SettingsFragment; -import org.mian.gitnex.helpers.AppDatabaseSettings; -import org.mian.gitnex.helpers.SnackBar; - -/** - * @author M M Arif - */ -public class SettingsCodeEditorActivity extends BaseActivity { - - private static String[] colorList; - private static int colorSelectedChoice; - private static String[] indentationList; - private static int indentationSelectedChoice; - private static String[] indentationTabsList; - private static int indentationTabsSelectedChoice; - - @Override - public void onCreate(Bundle savedInstanceState) { - - super.onCreate(savedInstanceState); - - ActivitySettingsCodeEditorBinding activitySettingsCodeEditorBinding = - ActivitySettingsCodeEditorBinding.inflate(getLayoutInflater()); - setContentView(activitySettingsCodeEditorBinding.getRoot()); - - activitySettingsCodeEditorBinding.topAppBar.setNavigationOnClickListener(v -> finish()); - - // color selector dialog - colorList = getResources().getStringArray(R.array.ceColors); - colorSelectedChoice = - Integer.parseInt( - AppDatabaseSettings.getSettingsValue( - ctx, AppDatabaseSettings.APP_CE_SYNTAX_HIGHLIGHT_KEY)); - activitySettingsCodeEditorBinding.ceColorSelected.setText(colorList[colorSelectedChoice]); - - activitySettingsCodeEditorBinding.ceColorSelectionFrame.setOnClickListener( - view -> { - MaterialAlertDialogBuilder materialAlertDialogBuilder = - new MaterialAlertDialogBuilder(ctx) - .setTitle(R.string.ceSyntaxHighlightColor) - .setSingleChoiceItems( - colorList, - colorSelectedChoice, - (dialogInterfaceColor, i) -> { - colorSelectedChoice = i; - activitySettingsCodeEditorBinding.ceColorSelected - .setText(colorList[i]); - AppDatabaseSettings.updateSettingsValue( - ctx, - String.valueOf(i), - AppDatabaseSettings - .APP_CE_SYNTAX_HIGHLIGHT_KEY); - - SettingsFragment.refreshParent = true; - this.recreate(); - this.overridePendingTransition(0, 0); - dialogInterfaceColor.dismiss(); - SnackBar.success( - ctx, - findViewById(android.R.id.content), - getString(R.string.settingsSave)); - }); - - materialAlertDialogBuilder.create().show(); - }); - - // indentation selector dialog - indentationList = getResources().getStringArray(R.array.ceIndentation); - indentationSelectedChoice = - Integer.parseInt( - AppDatabaseSettings.getSettingsValue( - ctx, AppDatabaseSettings.APP_CE_INDENTATION_KEY)); - activitySettingsCodeEditorBinding.indentationSelected.setText( - indentationList[indentationSelectedChoice]); - - activitySettingsCodeEditorBinding.indentationSelectionFrame.setOnClickListener( - view -> { - MaterialAlertDialogBuilder materialAlertDialogBuilder = - new MaterialAlertDialogBuilder(ctx) - .setTitle(R.string.ceIndentation) - .setSingleChoiceItems( - indentationList, - indentationSelectedChoice, - (dialogInterfaceColor, i) -> { - indentationSelectedChoice = i; - activitySettingsCodeEditorBinding - .indentationSelected.setText( - indentationList[i]); - AppDatabaseSettings.updateSettingsValue( - ctx, - String.valueOf(i), - AppDatabaseSettings.APP_CE_INDENTATION_KEY); - - SettingsFragment.refreshParent = true; - this.recreate(); - this.overridePendingTransition(0, 0); - dialogInterfaceColor.dismiss(); - SnackBar.success( - ctx, - findViewById(android.R.id.content), - getString(R.string.settingsSave)); - }); - - materialAlertDialogBuilder.create().show(); - }); - - // indentation tabs selector dialog - if (indentationList[indentationSelectedChoice].startsWith("Tabs")) { - activitySettingsCodeEditorBinding.indentationTabsSelectionFrame.setVisibility( - View.VISIBLE); - } else { - activitySettingsCodeEditorBinding.indentationTabsSelectionFrame.setVisibility( - View.GONE); - } - - indentationTabsList = getResources().getStringArray(R.array.ceIndentationTabsWidth); - indentationTabsSelectedChoice = - Integer.parseInt( - AppDatabaseSettings.getSettingsValue( - ctx, AppDatabaseSettings.APP_CE_TABS_WIDTH_KEY)); - activitySettingsCodeEditorBinding.indentationTabsSelected.setText( - indentationTabsList[indentationTabsSelectedChoice]); - - activitySettingsCodeEditorBinding.indentationTabsSelectionFrame.setOnClickListener( - view -> { - MaterialAlertDialogBuilder materialAlertDialogBuilder = - new MaterialAlertDialogBuilder(ctx) - .setTitle(R.string.ceIndentationTabsWidth) - .setSingleChoiceItems( - indentationTabsList, - indentationTabsSelectedChoice, - (dialogInterfaceColor, i) -> { - indentationTabsSelectedChoice = i; - activitySettingsCodeEditorBinding - .indentationTabsSelected.setText( - indentationTabsList[i]); - AppDatabaseSettings.updateSettingsValue( - ctx, - String.valueOf(i), - AppDatabaseSettings.APP_CE_TABS_WIDTH_KEY); - - SettingsFragment.refreshParent = true; - this.recreate(); - this.overridePendingTransition(0, 0); - dialogInterfaceColor.dismiss(); - SnackBar.success( - ctx, - findViewById(android.R.id.content), - getString(R.string.settingsSave)); - }); - - materialAlertDialogBuilder.create().show(); - }); - } -} diff --git a/app/src/main/java/org/mian/gitnex/fragments/BottomSheetSettingsCodeEditorFragment.java b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetSettingsCodeEditorFragment.java new file mode 100644 index 00000000..fd9db2f0 --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetSettingsCodeEditorFragment.java @@ -0,0 +1,186 @@ +package org.mian.gitnex.fragments; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import com.google.android.material.bottomsheet.BottomSheetDialogFragment; +import org.mian.gitnex.R; +import org.mian.gitnex.databinding.BottomSheetSettingsCodeEditorBinding; +import org.mian.gitnex.helpers.AppDatabaseSettings; +import org.mian.gitnex.helpers.SnackBar; + +/** + * @author mmarif + */ +public class BottomSheetSettingsCodeEditorFragment extends BottomSheetDialogFragment { + + private BottomSheetSettingsCodeEditorBinding binding; + private static int colorSelectedChoice; + private static int indentationSelectedChoice; + private static int indentationTabsSelectedChoice; + private static String[] indentationList; + + @Nullable @Override + public View onCreateView( + @NonNull LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + binding = BottomSheetSettingsCodeEditorBinding.inflate(inflater, container, false); + + indentationList = getResources().getStringArray(R.array.ceIndentation); + colorSelectedChoice = + Integer.parseInt( + AppDatabaseSettings.getSettingsValue( + requireContext(), AppDatabaseSettings.APP_CE_SYNTAX_HIGHLIGHT_KEY)); + indentationSelectedChoice = + Integer.parseInt( + AppDatabaseSettings.getSettingsValue( + requireContext(), AppDatabaseSettings.APP_CE_INDENTATION_KEY)); + indentationTabsSelectedChoice = + Integer.parseInt( + AppDatabaseSettings.getSettingsValue( + requireContext(), AppDatabaseSettings.APP_CE_TABS_WIDTH_KEY)); + + setColorChipSelection(colorSelectedChoice); + setIndentationChipSelection(indentationSelectedChoice); + setIndentationTabsChipSelection(indentationTabsSelectedChoice); + + updateTabsWidthVisibility(); + + binding.ceColorChipGroup.setOnCheckedStateChangeListener( + (group, checkedIds) -> { + if (checkedIds.size() == 1) { + int newSelection = getColorChipPosition(checkedIds.get(0)); + if (newSelection != colorSelectedChoice) { + colorSelectedChoice = newSelection; + AppDatabaseSettings.updateSettingsValue( + requireContext(), + String.valueOf(newSelection), + AppDatabaseSettings.APP_CE_SYNTAX_HIGHLIGHT_KEY); + SettingsFragment.refreshParent = true; + SnackBar.success( + requireContext(), + requireActivity().findViewById(android.R.id.content), + getString(R.string.settingsSave)); + } + } + }); + + binding.indentationChipGroup.setOnCheckedStateChangeListener( + (group, checkedIds) -> { + if (checkedIds.size() == 1) { + int newSelection = getIndentationChipPosition(checkedIds.get(0)); + if (newSelection != indentationSelectedChoice) { + indentationSelectedChoice = newSelection; + AppDatabaseSettings.updateSettingsValue( + requireContext(), + String.valueOf(newSelection), + AppDatabaseSettings.APP_CE_INDENTATION_KEY); + updateTabsWidthVisibility(); + SettingsFragment.refreshParent = true; + SnackBar.success( + requireContext(), + requireActivity().findViewById(android.R.id.content), + getString(R.string.settingsSave)); + } + } + }); + + binding.indentationTabsChipGroup.setOnCheckedStateChangeListener( + (group, checkedIds) -> { + if (checkedIds.size() == 1) { + int newSelection = getIndentationTabsChipPosition(checkedIds.get(0)); + if (newSelection != indentationTabsSelectedChoice) { + indentationTabsSelectedChoice = newSelection; + AppDatabaseSettings.updateSettingsValue( + requireContext(), + String.valueOf(newSelection), + AppDatabaseSettings.APP_CE_TABS_WIDTH_KEY); + SettingsFragment.refreshParent = true; + SnackBar.success( + requireContext(), + requireActivity().findViewById(android.R.id.content), + getString(R.string.settingsSave)); + } + } + }); + + return binding.getRoot(); + } + + private void setColorChipSelection(int position) { + switch (position) { + case 0: + binding.chipColorDark.setChecked(true); + break; + case 1: + binding.chipColorLight.setChecked(true); + break; + } + } + + private int getColorChipPosition(int checkedId) { + if (checkedId == R.id.chipColorDark) return 0; + if (checkedId == R.id.chipColorLight) return 1; + return colorSelectedChoice; + } + + private void setIndentationChipSelection(int position) { + switch (position) { + case 0: + binding.chipIndentSpaces.setChecked(true); + break; + case 1: + binding.chipIndentTabs.setChecked(true); + break; + } + } + + private int getIndentationChipPosition(int checkedId) { + if (checkedId == R.id.chipIndentSpaces) return 0; + if (checkedId == R.id.chipIndentTabs) return 1; + return indentationSelectedChoice; + } + + private void setIndentationTabsChipSelection(int position) { + switch (position) { + case 0: + binding.chipTabs2.setChecked(true); + break; + case 1: + binding.chipTabs4.setChecked(true); + break; + case 2: + binding.chipTabs6.setChecked(true); + break; + case 3: + binding.chipTabs8.setChecked(true); + break; + } + } + + private int getIndentationTabsChipPosition(int checkedId) { + if (checkedId == R.id.chipTabs2) return 0; + if (checkedId == R.id.chipTabs4) return 1; + if (checkedId == R.id.chipTabs6) return 2; + if (checkedId == R.id.chipTabs8) return 3; + return indentationTabsSelectedChoice; + } + + private void updateTabsWidthVisibility() { + boolean isTabsSelected = + indentationList[indentationSelectedChoice].startsWith( + getString(R.string.ceIndentationTabs)); + binding.indentationTabsSelectionFrame.setVisibility( + isTabsSelected ? View.VISIBLE : View.GONE); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + binding = null; + } +} diff --git a/app/src/main/java/org/mian/gitnex/fragments/SettingsFragment.java b/app/src/main/java/org/mian/gitnex/fragments/SettingsFragment.java index 9d9df833..b4bc944b 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/SettingsFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/SettingsFragment.java @@ -13,7 +13,6 @@ import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import org.mian.gitnex.R; import org.mian.gitnex.activities.SettingsAppearanceActivity; -import org.mian.gitnex.activities.SettingsCodeEditorActivity; import org.mian.gitnex.activities.SettingsGeneralActivity; import org.mian.gitnex.activities.SettingsSecurityActivity; import org.mian.gitnex.databinding.FragmentSettingsBinding; @@ -47,7 +46,12 @@ public class SettingsFragment extends Fragment { v1 -> startActivity(new Intent(ctx, SettingsAppearanceActivity.class))); fragmentSettingsBinding.codeEditorFrame.setOnClickListener( - v1 -> startActivity(new Intent(ctx, SettingsCodeEditorActivity.class))); + v1 -> + new BottomSheetSettingsCodeEditorFragment() + .show(getChildFragmentManager(), "BottomSheetSettingsCodeEditor")); + + /*fragmentSettingsBinding.codeEditorFrame.setOnClickListener( + v1 -> startActivity(new Intent(ctx, SettingsCodeEditorActivity.class)));*/ fragmentSettingsBinding.securityFrame.setOnClickListener( v1 -> startActivity(new Intent(ctx, SettingsSecurityActivity.class))); diff --git a/app/src/main/res/layout/activity_settings_code_editor.xml b/app/src/main/res/layout/activity_settings_code_editor.xml deleted file mode 100644 index cc39a461..00000000 --- a/app/src/main/res/layout/activity_settings_code_editor.xml +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/bottom_sheet_settings_code_editor.xml b/app/src/main/res/layout/bottom_sheet_settings_code_editor.xml new file mode 100644 index 00000000..33715647 --- /dev/null +++ b/app/src/main/res/layout/bottom_sheet_settings_code_editor.xml @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index bfec9aa8..185b8038 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -97,20 +97,20 @@ - Five O Clock - Blue Moon + @string/ceColorFive + @string/ceColorBlueMoon - Tabs - Spaces + @string/ceIndentationSpaces + @string/ceIndentationTabs - 2 - 4 - 6 - 8 + @string/ceIndentationTabsWidth2 + @string/ceIndentationTabsWidth4 + @string/ceIndentationTabsWidth6 + @string/ceIndentationTabsWidth8 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 708be06a..d5392e23 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -19,6 +19,14 @@ Feedback Where can I get an access token? • Log in to your account on your instance (Codeberg, etc.).
• Click on your user profile picture, then go to Settings.
• Under Applications, create a token with a name of your choice.
• Choose All (public, private, and limited).
• Under Select permissions, select Read and write for each dropdown.

Once created, copy and paste or type the token here along with the instance URL.]]>
+ Five O Clock + Blue Moon + Tabs + Spaces + 2 + 4 + 6 + 8 My Repositories