code editor settings choices

This commit is contained in:
M M Arif 2023-04-16 00:45:31 +05:00
parent 684a2f0776
commit 349b954dd5
10 changed files with 338 additions and 10 deletions

View File

@ -120,6 +120,9 @@
<activity
android:name=".activities.SettingsAppearanceActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|keyboard|keyboardHidden|navigation"/>
<activity
android:name=".activities.SettingsCodeEditorActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|keyboard|keyboardHidden|navigation"/>
<activity
android:name=".activities.ProfileActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|keyboard|keyboardHidden|navigation"/>

View File

@ -0,0 +1,139 @@
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.Toasty;
/**
* @author M M Arif
*/
public class SettingsCodeEditorActivity extends BaseActivity {
private static String[] colorList;
private static int colorSelectedChoice = 0;
private View.OnClickListener onClickListener;
private static String[] indentationList;
private static int indentationSelectedChoice = 0;
private static String[] indentationTabsList;
private static int indentationTabsSelectedChoice = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivitySettingsCodeEditorBinding activitySettingsCodeEditorBinding =
ActivitySettingsCodeEditorBinding.inflate(getLayoutInflater());
setContentView(activitySettingsCodeEditorBinding.getRoot());
initCloseListener();
activitySettingsCodeEditorBinding.close.setOnClickListener(onClickListener);
// color selector dialog
colorList = getResources().getStringArray(R.array.ceColors);
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]);
tinyDB.putInt("ceColorId", i);
SettingsFragment.refreshParent = true;
this.recreate();
this.overridePendingTransition(0, 0);
dialogInterfaceColor.dismiss();
Toasty.success(
appCtx,
getResources()
.getString(R.string.settingsSave));
});
materialAlertDialogBuilder.create().show();
});
// indentation selector dialog
indentationList = getResources().getStringArray(R.array.ceIndentation);
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]);
tinyDB.putInt("ceIndentationId", i);
SettingsFragment.refreshParent = true;
this.recreate();
this.overridePendingTransition(0, 0);
dialogInterfaceColor.dismiss();
Toasty.success(
appCtx,
getResources()
.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);
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]);
tinyDB.putInt("ceIndentationTabsId", i);
SettingsFragment.refreshParent = true;
this.recreate();
this.overridePendingTransition(0, 0);
dialogInterfaceColor.dismiss();
Toasty.success(
appCtx,
getResources()
.getString(R.string.settingsSave));
});
materialAlertDialogBuilder.create().show();
});
}
private void initCloseListener() {
onClickListener = view -> finish();
}
}

View File

@ -16,6 +16,7 @@ import org.mian.gitnex.R;
import org.mian.gitnex.activities.BaseActivity;
import org.mian.gitnex.activities.MainActivity;
import org.mian.gitnex.activities.SettingsAppearanceActivity;
import org.mian.gitnex.activities.SettingsCodeEditorActivity;
import org.mian.gitnex.activities.SettingsGeneralActivity;
import org.mian.gitnex.activities.SettingsNotificationsActivity;
import org.mian.gitnex.activities.SettingsSecurityActivity;
@ -61,7 +62,7 @@ public class SettingsFragment extends Fragment {
v1 -> startActivity(new Intent(ctx, SettingsAppearanceActivity.class)));
fragmentSettingsBinding.codeEditorFrame.setOnClickListener(
v1 -> startActivity(new Intent(ctx, SettingsAppearanceActivity.class)));
v1 -> startActivity(new Intent(ctx, SettingsCodeEditorActivity.class)));
fragmentSettingsBinding.securityFrame.setOnClickListener(
v1 -> startActivity(new Intent(ctx, SettingsSecurityActivity.class)));

View File

@ -95,7 +95,8 @@
app:endIconTint="?attr/iconsColor"
app:hintTextColor="?attr/hintColor"
app:startIconDrawable="@drawable/ic_link"
app:startIconTint="?attr/iconsColor">
app:startIconTint="?attr/iconsColor"
app:helperText="@string/instanceHelperText">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/instanceUrl"

View File

@ -97,7 +97,8 @@
app:endIconTint="?attr/iconsColor"
app:hintTextColor="?attr/hintColor"
app:startIconDrawable="@drawable/ic_link"
app:startIconTint="?attr/iconsColor">
app:startIconTint="?attr/iconsColor"
app:helperText="@string/instanceHelperText">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/instance_url"

View File

@ -0,0 +1,150 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/primaryBackgroundColor"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dimen10dp"
android:theme="@style/Widget.AppCompat.SearchView"
app:elevation="@dimen/dimen0dp">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/primaryBackgroundColor"
android:theme="@style/AppTheme.AppBarOverlay">
<ImageView
android:id="@+id/close"
android:layout_width="@dimen/dimen26dp"
android:layout_height="@dimen/dimen26dp"
android:layout_marginStart="@dimen/dimen16dp"
android:layout_marginEnd="@dimen/dimen16dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/close"
android:focusable="true"
android:gravity="center_vertical"
android:src="@drawable/ic_close"/>
<TextView
android:id="@+id/toolbar_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:maxLines="1"
android:text="@string/codeEditor"
android:textColor="?attr/primaryTextColor"
android:textSize="@dimen/dimen20sp"/>
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:id="@+id/ceColorSelectionFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dimen6dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:padding="@dimen/dimen16dp">
<TextView
android:id="@+id/ceColorHeaderSelector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dimen24dp"
android:layout_marginEnd="@dimen/dimen24dp"
android:text="@string/ceSyntaxHighlightColor"
android:textColor="?attr/primaryTextColor"
android:textSize="@dimen/dimen18sp"/>
<TextView
android:id="@+id/ceColorSelected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dimen24dp"
android:layout_marginEnd="@dimen/dimen24dp"
android:text="@string/themeSelectionSelectedText"
android:textColor="?attr/selectedTextColor"
android:textSize="@dimen/dimen16sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/indentationSelectionFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dimen6dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:padding="@dimen/dimen16dp">
<TextView
android:id="@+id/indentationHeaderSelector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dimen24dp"
android:layout_marginEnd="@dimen/dimen24dp"
android:text="@string/ceIndentation"
android:textColor="?attr/primaryTextColor"
android:textSize="@dimen/dimen18sp"/>
<TextView
android:id="@+id/indentationSelected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dimen24dp"
android:layout_marginEnd="@dimen/dimen24dp"
android:text="@string/settingsThemeTimeSelectedHint"
android:textColor="?attr/selectedTextColor"
android:textSize="@dimen/dimen16sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/indentationTabsSelectionFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dimen6dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:padding="@dimen/dimen16dp">
<TextView
android:id="@+id/indentationTabsHeaderSelector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dimen24dp"
android:layout_marginEnd="@dimen/dimen24dp"
android:text="@string/ceIndentationTabsWidth"
android:textColor="?attr/primaryTextColor"
android:textSize="@dimen/dimen18sp"/>
<TextView
android:id="@+id/indentationTabsSelected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dimen24dp"
android:layout_marginEnd="@dimen/dimen24dp"
android:text="@string/settingsThemeTimeSelectedHint"
android:textColor="?attr/selectedTextColor"
android:textSize="@dimen/dimen16sp"/>
</LinearLayout>
</LinearLayout>

View File

@ -129,10 +129,11 @@
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/donationLinkPatreon"
android:layout_width="@dimen/dimen150dp"
android:layout_width="@dimen/dimen0dp"
android:layout_height="@dimen/dimen60dp"
android:layout_marginEnd="@dimen/dimen4dp"
android:layout_marginStart="@dimen/dimen0dp"
android:layout_weight=".5"
android:stateListAnimator="@null"
android:text="@string/supportTextPatreon"
android:textStyle="bold"
@ -144,10 +145,11 @@
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/donationLinkBuyMeaCoffee"
android:layout_width="@dimen/dimen150dp"
android:layout_width="@dimen/dimen0dp"
android:layout_height="@dimen/dimen60dp"
android:layout_marginEnd="@dimen/dimen0dp"
android:layout_marginStart="@dimen/dimen6dp"
android:layout_weight=".5"
android:stateListAnimator="@null"
android:text="@string/supportTextBuyMeaCoffee"
android:textStyle="bold"
@ -169,10 +171,11 @@
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/translateLink"
android:layout_width="@dimen/dimen150dp"
android:layout_width="@dimen/dimen0dp"
android:layout_height="@dimen/dimen60dp"
android:layout_marginEnd="@dimen/dimen4dp"
android:layout_marginStart="@dimen/dimen0dp"
android:layout_weight=".5"
android:stateListAnimator="@null"
android:text="@string/translateWithCrowdin"
android:textStyle="bold"
@ -184,10 +187,11 @@
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/appWebsite"
android:layout_width="@dimen/dimen150dp"
android:layout_width="@dimen/dimen0dp"
android:layout_height="@dimen/dimen60dp"
android:layout_marginEnd="@dimen/dimen0dp"
android:layout_marginStart="@dimen/dimen6dp"
android:layout_weight=".5"
android:stateListAnimator="@null"
android:text="@string/websiteText"
android:textStyle="bold"
@ -209,10 +213,11 @@
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/feedback"
android:layout_width="@dimen/dimen150dp"
android:layout_width="@dimen/dimen0dp"
android:layout_height="@dimen/dimen60dp"
android:layout_marginEnd="@dimen/dimen4dp"
android:layout_marginStart="@dimen/dimen0dp"
android:layout_weight=".5"
android:stateListAnimator="@null"
android:text="@string/feedbackText"
android:textStyle="bold"
@ -221,6 +226,12 @@
app:iconTint="?attr/materialCardBackgroundColor"
android:backgroundTint="?attr/fabColor"
app:icon="@drawable/ic_feedback" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_weight=".5" />
</LinearLayout>

View File

@ -169,7 +169,7 @@
android:layout_gravity="center_vertical"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:text="@string/appearanceHintText"
android:text="@string/codeEditorHintText"
android:textColor="?attr/primaryTextColor"
android:textSize="12sp"/>

View File

@ -90,4 +90,21 @@
<item>500 MB</item>
<item>1 GB</item>
</string-array>
<string-array name="ceColors">
<item>Five O Clock</item>
<item>Monro</item>
</string-array>
<string-array name="ceIndentation">
<item>Tabs</item>
<item>Spaces</item>
</string-array>
<string-array name="ceIndentationTabsWidth">
<item>2</item>
<item>4</item>
<item>6</item>
<item>8</item>
</string-array>
</resources>

View File

@ -8,7 +8,7 @@
<string name="commitPage" translatable="false">Your Instance Version</string>
<string name="supportLinkPatreon" translatable="false">https://www.patreon.com/mmarif</string>
<string name="supportLinkBuyMeaCoffee" translatable="false">https://www.buymeacoffee.com/mmarif</string>
<string name="feedbackLink" translatable="false">https://www.buymeacoffee.com/mmarif</string>
<string name="feedbackLink" translatable="false">https://cloud.swatian.com/apps/forms/s/xe7KekTNKgrj58EK6WHQyJDf</string>
<string name="appVersionBuild" translatable="false">%s / %d</string>
<string name="appDesc" translatable="false">GitNex is a free, open-source Android client for Git repository management tools Forgejo and Gitea. GitNex is Licensed under GPLv3.\n\nThanks to all the contributors and donators for your generous work and donations.</string>
<string name="crowdInLink" translatable="false">https://crowdin.com/project/gitnex</string>
@ -89,6 +89,7 @@
<string name="emptyFieldUsername">Username is required</string>
<string name="emptyFieldPassword">Password is required</string>
<string name="protocolEmptyError">Protocol is required</string>
<string name="instanceHelperText">Enter URL without http or https. Example: codeberg.org</string>
<string name="checkNetConnection">Cannot access network, please check your Internet connection</string>
@ -250,6 +251,9 @@
<string name="settingsBiometricHeader">Biometric Support</string>
<string name="settingsLabelsInListHeader">Labels With Text Support</string>
<string name="settingsLabelsInListHint">Enabling this will show labels with text in issues and pr lists, default are color dots</string>
<string name="ceSyntaxHighlightColor">Syntax Highlighting Color</string>
<string name="ceIndentation">Indentation</string>
<string name="ceIndentationTabsWidth">Tabs Width</string>
<!-- settings -->
<string name="noMoreData">No more data available</string>
@ -628,6 +632,7 @@
<string name="reportsHintText">Crash reports</string>
<string name="rateAppHintText">If you like GitNex you can give it a thumbs up</string>
<string name="aboutAppHintText">App version, build, user instance version</string>
<string name="codeEditorHintText">Syntax color, indentation</string>
<string name="archivedRepository">Archived</string>
<string name="archivedRepositoryMessage">This repo is archived. You can view files, but cannot push or open issues/pull-requests.</string>