mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2024-12-16 15:48:13 +08:00
Themes for source code in file viewer (#403)
reformat code move from else-if to switch-case Merge branch 'master' into 396-themes-file-veiwer Merge branch 'master' into 396-themes-file-veiwer Make string translatable false Themes for source code in file viewer Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/403 Reviewed-by: 6543 <6543@noreply.gitea.io>
This commit is contained in:
parent
008ffaa553
commit
539c5be4b5
@ -69,7 +69,8 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
private static final int PERMISSION_REQUEST_CODE = 1;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId(){
|
||||
protected int getLayoutResourceId() {
|
||||
|
||||
return R.layout.activity_file_view;
|
||||
}
|
||||
|
||||
@ -115,7 +116,7 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
singleFileName = singleFileName.startsWith("/") ? singleFileName.substring(1) : singleFileName;
|
||||
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
catch(UnsupportedEncodingException e) {
|
||||
|
||||
assert singleFileName != null;
|
||||
Log.i("singleFileName", singleFileName);
|
||||
@ -132,17 +133,14 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(getApplicationContext());
|
||||
|
||||
Call<Files> call = RetrofitClient
|
||||
.getInstance(instanceUrl, getApplicationContext())
|
||||
.getApiInterface()
|
||||
.getSingleFileContents(token, owner, repo, filename);
|
||||
Call<Files> call = RetrofitClient.getInstance(instanceUrl, getApplicationContext()).getApiInterface().getSingleFileContents(token, owner, repo, filename);
|
||||
|
||||
call.enqueue(new Callback<Files>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<Files> call, @NonNull retrofit2.Response<Files> response) {
|
||||
|
||||
if (response.code() == 200) {
|
||||
if(response.code() == 200) {
|
||||
|
||||
AppUtil appUtil = new AppUtil();
|
||||
assert response.body() != null;
|
||||
@ -168,19 +166,38 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
imageView.setImageDrawable(imageDrawable);
|
||||
|
||||
}
|
||||
else if (appUtil.sourceCodeExtension(fileExtension)) { // file is sourcecode
|
||||
else if(appUtil.sourceCodeExtension(fileExtension)) { // file is sourcecode
|
||||
|
||||
imageView.setVisibility(View.GONE);
|
||||
singleFileContentsFrame.setVisibility(View.GONE);
|
||||
pdfViewFrame.setVisibility(View.GONE);
|
||||
singleCodeContents.setVisibility(View.VISIBLE);
|
||||
|
||||
singleCodeContents.setTheme(Theme.GRUVBOX_DARK);
|
||||
switch(tinyDb.getInt("fileviewerSourceCodeThemeId")) {
|
||||
case 1:
|
||||
singleCodeContents.setTheme(Theme.ARDUINO_LIGHT);
|
||||
break;
|
||||
case 2:
|
||||
singleCodeContents.setTheme(Theme.GITHUB);
|
||||
break;
|
||||
case 3:
|
||||
singleCodeContents.setTheme(Theme.FAR);
|
||||
break;
|
||||
case 4:
|
||||
singleCodeContents.setTheme(Theme.IR_BLACK);
|
||||
break;
|
||||
case 5:
|
||||
singleCodeContents.setTheme(Theme.ANDROID_STUDIO);
|
||||
break;
|
||||
default:
|
||||
singleCodeContents.setTheme(Theme.MONOKAI_SUBLIME);
|
||||
}
|
||||
|
||||
singleCodeContents.setShowLineNumbers(true);
|
||||
singleCodeContents.setSource(appUtil.decodeBase64(response.body().getContent()));
|
||||
|
||||
}
|
||||
else if (appUtil.pdfExtension(fileExtension)) { // file is pdf
|
||||
else if(appUtil.pdfExtension(fileExtension)) { // file is pdf
|
||||
|
||||
imageView.setVisibility(View.GONE);
|
||||
singleFileContentsFrame.setVisibility(View.GONE);
|
||||
@ -190,26 +207,10 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
pdfNightMode = tinyDb.getBoolean("enablePdfMode");
|
||||
|
||||
decodedPdf = Base64.decode(response.body().getContent(), Base64.DEFAULT);
|
||||
pdfView.fromBytes(decodedPdf)
|
||||
.enableSwipe(true)
|
||||
.swipeHorizontal(false)
|
||||
.enableDoubletap(true)
|
||||
.defaultPage(0)
|
||||
.enableAnnotationRendering(false)
|
||||
.password(null)
|
||||
.scrollHandle(null)
|
||||
.enableAntialiasing(true)
|
||||
.spacing(0)
|
||||
.autoSpacing(true)
|
||||
.pageFitPolicy(FitPolicy.WIDTH)
|
||||
.fitEachPage(true)
|
||||
.pageSnap(false)
|
||||
.pageFling(true)
|
||||
.nightMode(pdfNightMode)
|
||||
.load();
|
||||
pdfView.fromBytes(decodedPdf).enableSwipe(true).swipeHorizontal(false).enableDoubletap(true).defaultPage(0).enableAnnotationRendering(false).password(null).scrollHandle(null).enableAntialiasing(true).spacing(0).autoSpacing(true).pageFitPolicy(FitPolicy.WIDTH).fitEachPage(true).pageSnap(false).pageFling(true).nightMode(pdfNightMode).load();
|
||||
|
||||
}
|
||||
else if (appUtil.excludeFilesInFileViewerExtension(fileExtension)) { // files need to be excluded
|
||||
else if(appUtil.excludeFilesInFileViewerExtension(fileExtension)) { // files need to be excluded
|
||||
|
||||
imageView.setVisibility(View.GONE);
|
||||
singleCodeContents.setVisibility(View.GONE);
|
||||
@ -241,10 +242,7 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else if(response.code() == 403) {
|
||||
@ -267,6 +265,7 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<Files> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
}
|
||||
});
|
||||
@ -275,6 +274,7 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
||||
return true;
|
||||
@ -285,7 +285,7 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
|
||||
int id = item.getItemId();
|
||||
|
||||
switch (id) {
|
||||
switch(id) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
@ -302,21 +302,18 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
@Override
|
||||
public void onButtonClicked(String text) {
|
||||
|
||||
switch (text) {
|
||||
switch(text) {
|
||||
case "downloadFile":
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23)
|
||||
{
|
||||
if (checkPermission())
|
||||
{
|
||||
if(Build.VERSION.SDK_INT >= 23) {
|
||||
if(checkPermission()) {
|
||||
requestFileDownload();
|
||||
}
|
||||
else {
|
||||
requestPermission();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
requestFileDownload();
|
||||
}
|
||||
break;
|
||||
@ -346,7 +343,7 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
Toasty.info(getApplicationContext(), getString(R.string.downloadFileSaved));
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch(IOException e) {
|
||||
Log.e("errorFileDownloading", Objects.requireNonNull(e.getMessage()));
|
||||
}
|
||||
|
||||
@ -358,19 +355,22 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
}
|
||||
|
||||
private boolean checkPermission() {
|
||||
|
||||
int result = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
return result == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
private void requestPermission() {
|
||||
|
||||
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
|
||||
switch(requestCode) {
|
||||
case PERMISSION_REQUEST_CODE:
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
Log.i("PermissionsCheck", "Permission Granted");
|
||||
}
|
||||
else {
|
||||
@ -381,9 +381,12 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
|
||||
onClickListener = new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
getIntent().removeExtra("singleFileName");
|
||||
finish();
|
||||
}
|
||||
|
@ -47,6 +47,9 @@ public class SettingsFragment extends Fragment {
|
||||
private static String[] themeList = {"Dark", "Light", "Auto (Day/Night)"};
|
||||
private static int themeSelectedChoice = 0;
|
||||
|
||||
private static String[] fileveiwerSourceCodeThemesList = {"Sublime", "Arduino Light", "Github", "Far ", "Ir Black", "Android Studio"};
|
||||
private static int fileveiwerSourceCodeThemesSelectedChoice = 0;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@ -60,6 +63,7 @@ public class SettingsFragment extends Fragment {
|
||||
final TextView homeScreenSelected = v.findViewById(R.id.homeScreenSelected); // setter for home screen
|
||||
final TextView customFontSelected = v.findViewById(R.id.customFontSelected); // setter for custom font
|
||||
final TextView themeSelected = v.findViewById(R.id.themeSelected); // setter for theme
|
||||
final TextView fileveiwerSourceCodeThemesSelected = v.findViewById(R.id.sourceCodeThemeSelected); // setter for fileviewer theme
|
||||
|
||||
LinearLayout langFrame = v.findViewById(R.id.langFrame);
|
||||
LinearLayout timeFrame = v.findViewById(R.id.timeFrame);
|
||||
@ -68,6 +72,7 @@ public class SettingsFragment extends Fragment {
|
||||
LinearLayout customFontFrame = v.findViewById(R.id.customFontFrame);
|
||||
LinearLayout themeFrame = v.findViewById(R.id.themeSelectionFrame);
|
||||
LinearLayout certsFrame = v.findViewById(R.id.certsFrame);
|
||||
LinearLayout sourceCodeThemeFrame = v.findViewById(R.id.sourceCodeThemeFrame);
|
||||
|
||||
Switch counterBadgesSwitch = v.findViewById(R.id.switchCounterBadge);
|
||||
Switch pdfModeSwitch = v.findViewById(R.id.switchPdfMode);
|
||||
@ -107,6 +112,10 @@ public class SettingsFragment extends Fragment {
|
||||
themeSelected.setText(tinyDb.getString("themeStr"));
|
||||
}
|
||||
|
||||
if(!tinyDb.getString("fileviewerSourceCodeThemeStr").isEmpty()) {
|
||||
fileveiwerSourceCodeThemesSelected.setText(tinyDb.getString("fileviewerSourceCodeThemeStr"));
|
||||
}
|
||||
|
||||
if(langSelectedChoice == 0) {
|
||||
langSelectedChoice = tinyDb.getInt("langId");
|
||||
}
|
||||
@ -131,6 +140,10 @@ public class SettingsFragment extends Fragment {
|
||||
themeSelectedChoice = tinyDb.getInt("themeId");
|
||||
}
|
||||
|
||||
if(fileveiwerSourceCodeThemesSelectedChoice == 0) {
|
||||
fileveiwerSourceCodeThemesSelectedChoice = tinyDb.getInt("fileviewerThemeId");
|
||||
}
|
||||
|
||||
if(tinyDb.getBoolean("enableCounterBadges")) {
|
||||
counterBadgesSwitch.setChecked(true);
|
||||
}
|
||||
@ -145,6 +158,38 @@ public class SettingsFragment extends Fragment {
|
||||
pdfModeSwitch.setChecked(false);
|
||||
}
|
||||
|
||||
// fileviewer srouce code theme selection dialog
|
||||
sourceCodeThemeFrame.setOnClickListener(view -> {
|
||||
|
||||
AlertDialog.Builder fvtsBuilder = new AlertDialog.Builder(ctx);
|
||||
|
||||
fvtsBuilder.setTitle(R.string.fileviewerSourceCodeThemeSelectorDialogTitle);
|
||||
if(fileveiwerSourceCodeThemesSelectedChoice != -1) {
|
||||
fvtsBuilder.setCancelable(true);
|
||||
}
|
||||
else {
|
||||
fvtsBuilder.setCancelable(false);
|
||||
}
|
||||
|
||||
fvtsBuilder.setSingleChoiceItems(fileveiwerSourceCodeThemesList, fileveiwerSourceCodeThemesSelectedChoice, (dialogInterfaceTheme, i) -> {
|
||||
|
||||
fileveiwerSourceCodeThemesSelectedChoice = i;
|
||||
fileveiwerSourceCodeThemesSelected.setText(fileveiwerSourceCodeThemesList[i]);
|
||||
tinyDb.putString("fileviewerSourceCodeThemeStr", fileveiwerSourceCodeThemesList[i]);
|
||||
tinyDb.putInt("fileviewerSourceCodeThemeId", i);
|
||||
|
||||
Objects.requireNonNull(getActivity()).recreate();
|
||||
getActivity().overridePendingTransition(0, 0);
|
||||
dialogInterfaceTheme.dismiss();
|
||||
Toasty.info(getContext(), getResources().getString(R.string.settingsSave));
|
||||
|
||||
});
|
||||
|
||||
AlertDialog cfDialog = fvtsBuilder.create();
|
||||
cfDialog.show();
|
||||
|
||||
});
|
||||
|
||||
// certs deletion
|
||||
certsFrame.setOnClickListener(v1 -> {
|
||||
|
||||
|
@ -49,4 +49,34 @@
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/sourceCodeThemeFrame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sourceCodeThemeHeader"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginStart="44dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:text="@string/settingsFileviewerSourceCodeHeaderText"
|
||||
android:textColor="?attr/primaryTextColor"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sourceCodeThemeSelected"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginStart="44dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:text="@string/settingsFileviewerSourceCodeSelectedText"
|
||||
android:textColor="?attr/selectedTextColor"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -279,6 +279,9 @@
|
||||
<string name="settingsPdfModeHeaderText">PDF Night Mode</string>
|
||||
<string name="fileViewerHeader">File Viewer</string>
|
||||
<string name="settingsCounterBadges">Counter Badges</string>
|
||||
<string name="settingsFileviewerSourceCodeHeaderText">Source Code Theme</string>
|
||||
<string name="settingsFileviewerSourceCodeSelectedText" translatable="false">Sublime</string>
|
||||
<string name="fileviewerSourceCodeThemeSelectorDialogTitle">Select Source Code Theme</string>
|
||||
<!-- settings -->
|
||||
|
||||
<string name="noMoreData">No more data available</string>
|
||||
|
Loading…
Reference in New Issue
Block a user