mirror of
https://codeberg.org/gitnex/GitNex
synced 2025-03-10 00:20:16 +01: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
@ -54,340 +54,343 @@ import retrofit2.Callback;
|
|||||||
|
|
||||||
public class FileViewActivity extends BaseActivity implements BottomSheetFileViewerFragment.BottomSheetListener {
|
public class FileViewActivity extends BaseActivity implements BottomSheetFileViewerFragment.BottomSheetListener {
|
||||||
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
private TextView singleFileContents;
|
private TextView singleFileContents;
|
||||||
private LinearLayout singleFileContentsFrame;
|
private LinearLayout singleFileContentsFrame;
|
||||||
private HighlightJsView singleCodeContents;
|
private HighlightJsView singleCodeContents;
|
||||||
private PhotoView imageView;
|
private PhotoView imageView;
|
||||||
final Context ctx = this;
|
final Context ctx = this;
|
||||||
private ProgressBar mProgressBar;
|
private ProgressBar mProgressBar;
|
||||||
private byte[] imageData;
|
private byte[] imageData;
|
||||||
private PDFView pdfView;
|
private PDFView pdfView;
|
||||||
private LinearLayout pdfViewFrame;
|
private LinearLayout pdfViewFrame;
|
||||||
private byte[] decodedPdf;
|
private byte[] decodedPdf;
|
||||||
private Boolean pdfNightMode;
|
private Boolean pdfNightMode;
|
||||||
private static final int PERMISSION_REQUEST_CODE = 1;
|
private static final int PERMISSION_REQUEST_CODE = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getLayoutResourceId(){
|
protected int getLayoutResourceId() {
|
||||||
return R.layout.activity_file_view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return R.layout.activity_file_view;
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
}
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
@Override
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(getApplicationContext());
|
super.onCreate(savedInstanceState);
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
String[] parts = repoFullName.split("/");
|
setSupportActionBar(toolbar);
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
final TinyDB tinyDb = new TinyDB(getApplicationContext());
|
||||||
singleFileContents = findViewById(R.id.singleFileContents);
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
singleCodeContents = findViewById(R.id.singleCodeContents);
|
String[] parts = repoFullName.split("/");
|
||||||
imageView = findViewById(R.id.imageView);
|
final String repoOwner = parts[0];
|
||||||
mProgressBar = findViewById(R.id.progress_bar);
|
final String repoName = parts[1];
|
||||||
pdfView = findViewById(R.id.pdfView);
|
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||||
pdfViewFrame = findViewById(R.id.pdfViewFrame);
|
final String loginUid = tinyDb.getString("loginUid");
|
||||||
singleFileContentsFrame = findViewById(R.id.singleFileContentsFrame);
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||||
|
|
||||||
String singleFileName = getIntent().getStringExtra("singleFileName");
|
ImageView closeActivity = findViewById(R.id.close);
|
||||||
|
singleFileContents = findViewById(R.id.singleFileContents);
|
||||||
|
singleCodeContents = findViewById(R.id.singleCodeContents);
|
||||||
|
imageView = findViewById(R.id.imageView);
|
||||||
|
mProgressBar = findViewById(R.id.progress_bar);
|
||||||
|
pdfView = findViewById(R.id.pdfView);
|
||||||
|
pdfViewFrame = findViewById(R.id.pdfViewFrame);
|
||||||
|
singleFileContentsFrame = findViewById(R.id.singleFileContentsFrame);
|
||||||
|
|
||||||
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
String singleFileName = getIntent().getStringExtra("singleFileName");
|
||||||
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
|
|
||||||
|
|
||||||
initCloseListener();
|
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
|
||||||
|
|
||||||
tinyDb.putString("downloadFileContents", "");
|
|
||||||
|
|
||||||
try {
|
initCloseListener();
|
||||||
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
singleFileName = URLDecoder.decode(singleFileName, "UTF-8");
|
|
||||||
singleFileName = singleFileName.replaceAll("//", "/");
|
|
||||||
singleFileName = singleFileName.startsWith("/") ? singleFileName.substring(1) : singleFileName;
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (UnsupportedEncodingException e) {
|
|
||||||
|
|
||||||
assert singleFileName != null;
|
tinyDb.putString("downloadFileContents", "");
|
||||||
Log.i("singleFileName", singleFileName);
|
|
||||||
|
|
||||||
}
|
try {
|
||||||
|
|
||||||
toolbar_title.setText(singleFileName);
|
|
||||||
|
|
||||||
getSingleFileContents(instanceUrl, instanceToken, repoOwner, repoName, singleFileName);
|
singleFileName = URLDecoder.decode(singleFileName, "UTF-8");
|
||||||
|
singleFileName = singleFileName.replaceAll("//", "/");
|
||||||
}
|
singleFileName = singleFileName.startsWith("/") ? singleFileName.substring(1) : singleFileName;
|
||||||
|
|
||||||
private void getSingleFileContents(String instanceUrl, String token, final String owner, String repo, final String filename) {
|
}
|
||||||
|
catch(UnsupportedEncodingException e) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(getApplicationContext());
|
assert singleFileName != null;
|
||||||
|
Log.i("singleFileName", singleFileName);
|
||||||
|
|
||||||
Call<Files> call = RetrofitClient
|
}
|
||||||
.getInstance(instanceUrl, getApplicationContext())
|
|
||||||
.getApiInterface()
|
|
||||||
.getSingleFileContents(token, owner, repo, filename);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<Files>() {
|
toolbar_title.setText(singleFileName);
|
||||||
|
|
||||||
@Override
|
getSingleFileContents(instanceUrl, instanceToken, repoOwner, repoName, singleFileName);
|
||||||
public void onResponse(@NonNull Call<Files> call, @NonNull retrofit2.Response<Files> response) {
|
|
||||||
|
|
||||||
if (response.code() == 200) {
|
}
|
||||||
|
|
||||||
AppUtil appUtil = new AppUtil();
|
private void getSingleFileContents(String instanceUrl, String token, final String owner, String repo, final String filename) {
|
||||||
assert response.body() != null;
|
|
||||||
|
|
||||||
if(!response.body().getContent().equals("")) {
|
final TinyDB tinyDb = new TinyDB(getApplicationContext());
|
||||||
|
|
||||||
String fileExtension = FileUtils.getExtension(filename);
|
Call<Files> call = RetrofitClient.getInstance(instanceUrl, getApplicationContext()).getApiInterface().getSingleFileContents(token, owner, repo, filename);
|
||||||
mProgressBar.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
// download file meta
|
call.enqueue(new Callback<Files>() {
|
||||||
tinyDb.putString("downloadFileName", filename);
|
|
||||||
tinyDb.putString("downloadFileContents", response.body().getContent());
|
|
||||||
|
|
||||||
if(appUtil.imageExtension(fileExtension)) { // file is image
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<Files> call, @NonNull retrofit2.Response<Files> response) {
|
||||||
|
|
||||||
singleFileContentsFrame.setVisibility(View.GONE);
|
if(response.code() == 200) {
|
||||||
singleCodeContents.setVisibility(View.GONE);
|
|
||||||
pdfViewFrame.setVisibility(View.GONE);
|
|
||||||
imageView.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
imageData = Base64.decode(response.body().getContent(), Base64.DEFAULT);
|
AppUtil appUtil = new AppUtil();
|
||||||
Drawable imageDrawable = new BitmapDrawable(getResources(), BitmapFactory.decodeByteArray(imageData, 0, imageData.length));
|
assert response.body() != null;
|
||||||
imageView.setImageDrawable(imageDrawable);
|
|
||||||
|
|
||||||
}
|
if(!response.body().getContent().equals("")) {
|
||||||
else if (appUtil.sourceCodeExtension(fileExtension)) { // file is sourcecode
|
|
||||||
|
|
||||||
imageView.setVisibility(View.GONE);
|
String fileExtension = FileUtils.getExtension(filename);
|
||||||
singleFileContentsFrame.setVisibility(View.GONE);
|
mProgressBar.setVisibility(View.GONE);
|
||||||
pdfViewFrame.setVisibility(View.GONE);
|
|
||||||
singleCodeContents.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
singleCodeContents.setTheme(Theme.GRUVBOX_DARK);
|
// download file meta
|
||||||
singleCodeContents.setShowLineNumbers(true);
|
tinyDb.putString("downloadFileName", filename);
|
||||||
singleCodeContents.setSource(appUtil.decodeBase64(response.body().getContent()));
|
tinyDb.putString("downloadFileContents", response.body().getContent());
|
||||||
|
|
||||||
}
|
if(appUtil.imageExtension(fileExtension)) { // file is image
|
||||||
else if (appUtil.pdfExtension(fileExtension)) { // file is pdf
|
|
||||||
|
|
||||||
imageView.setVisibility(View.GONE);
|
singleFileContentsFrame.setVisibility(View.GONE);
|
||||||
singleFileContentsFrame.setVisibility(View.GONE);
|
singleCodeContents.setVisibility(View.GONE);
|
||||||
singleCodeContents.setVisibility(View.GONE);
|
pdfViewFrame.setVisibility(View.GONE);
|
||||||
pdfViewFrame.setVisibility(View.VISIBLE);
|
imageView.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
pdfNightMode = tinyDb.getBoolean("enablePdfMode");
|
imageData = Base64.decode(response.body().getContent(), Base64.DEFAULT);
|
||||||
|
Drawable imageDrawable = new BitmapDrawable(getResources(), BitmapFactory.decodeByteArray(imageData, 0, imageData.length));
|
||||||
|
imageView.setImageDrawable(imageDrawable);
|
||||||
|
|
||||||
decodedPdf = Base64.decode(response.body().getContent(), Base64.DEFAULT);
|
}
|
||||||
pdfView.fromBytes(decodedPdf)
|
else if(appUtil.sourceCodeExtension(fileExtension)) { // file is sourcecode
|
||||||
.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();
|
|
||||||
|
|
||||||
}
|
imageView.setVisibility(View.GONE);
|
||||||
else if (appUtil.excludeFilesInFileViewerExtension(fileExtension)) { // files need to be excluded
|
singleFileContentsFrame.setVisibility(View.GONE);
|
||||||
|
pdfViewFrame.setVisibility(View.GONE);
|
||||||
|
singleCodeContents.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
imageView.setVisibility(View.GONE);
|
switch(tinyDb.getInt("fileviewerSourceCodeThemeId")) {
|
||||||
singleCodeContents.setVisibility(View.GONE);
|
case 1:
|
||||||
pdfViewFrame.setVisibility(View.GONE);
|
singleCodeContents.setTheme(Theme.ARDUINO_LIGHT);
|
||||||
singleFileContentsFrame.setVisibility(View.VISIBLE);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
singleFileContents.setText(getResources().getString(R.string.excludeFilesInFileviewer));
|
singleCodeContents.setShowLineNumbers(true);
|
||||||
singleFileContents.setGravity(Gravity.CENTER);
|
singleCodeContents.setSource(appUtil.decodeBase64(response.body().getContent()));
|
||||||
singleFileContents.setTypeface(null, Typeface.BOLD);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else { // file type not known - plain text view
|
else if(appUtil.pdfExtension(fileExtension)) { // file is pdf
|
||||||
|
|
||||||
imageView.setVisibility(View.GONE);
|
imageView.setVisibility(View.GONE);
|
||||||
singleCodeContents.setVisibility(View.GONE);
|
singleFileContentsFrame.setVisibility(View.GONE);
|
||||||
pdfViewFrame.setVisibility(View.GONE);
|
singleCodeContents.setVisibility(View.GONE);
|
||||||
singleFileContentsFrame.setVisibility(View.VISIBLE);
|
pdfViewFrame.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
singleFileContents.setText(appUtil.decodeBase64(response.body().getContent()));
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else if(appUtil.excludeFilesInFileViewerExtension(fileExtension)) { // files need to be excluded
|
||||||
singleFileContents.setText("");
|
|
||||||
mProgressBar.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
imageView.setVisibility(View.GONE);
|
||||||
else if(response.code() == 401) {
|
singleCodeContents.setVisibility(View.GONE);
|
||||||
|
pdfViewFrame.setVisibility(View.GONE);
|
||||||
|
singleFileContentsFrame.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
singleFileContents.setText(getResources().getString(R.string.excludeFilesInFileviewer));
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
singleFileContents.setGravity(Gravity.CENTER);
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
singleFileContents.setTypeface(null, Typeface.BOLD);
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 403) {
|
else { // file type not known - plain text view
|
||||||
|
|
||||||
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
|
imageView.setVisibility(View.GONE);
|
||||||
|
singleCodeContents.setVisibility(View.GONE);
|
||||||
|
pdfViewFrame.setVisibility(View.GONE);
|
||||||
|
singleFileContentsFrame.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
}
|
singleFileContents.setText(appUtil.decodeBase64(response.body().getContent()));
|
||||||
else if(response.code() == 404) {
|
|
||||||
|
|
||||||
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
|
||||||
Toasty.info(getApplicationContext(), getString(R.string.labelGeneralError));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
@Override
|
singleFileContents.setText("");
|
||||||
public void onFailure(@NonNull Call<Files> call, @NonNull Throwable t) {
|
mProgressBar.setVisibility(View.GONE);
|
||||||
Log.e("onFailure", t.toString());
|
}
|
||||||
}
|
|
||||||
});
|
}
|
||||||
|
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));
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
}
|
||||||
MenuInflater inflater = getMenuInflater();
|
else if(response.code() == 403) {
|
||||||
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
|
||||||
return true;
|
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
|
||||||
}
|
|
||||||
|
}
|
||||||
@Override
|
else if(response.code() == 404) {
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
|
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
|
||||||
int id = item.getItemId();
|
|
||||||
|
}
|
||||||
switch (id) {
|
else {
|
||||||
case android.R.id.home:
|
|
||||||
finish();
|
Toasty.info(getApplicationContext(), getString(R.string.labelGeneralError));
|
||||||
return true;
|
|
||||||
case R.id.genericMenu:
|
}
|
||||||
BottomSheetFileViewerFragment bottomSheet = new BottomSheetFileViewerFragment();
|
|
||||||
bottomSheet.show(getSupportFragmentManager(), "fileViewerBottomSheet");
|
}
|
||||||
return true;
|
|
||||||
default:
|
@Override
|
||||||
return super.onOptionsItemSelected(item);
|
public void onFailure(@NonNull Call<Files> call, @NonNull Throwable t) {
|
||||||
}
|
|
||||||
|
Log.e("onFailure", t.toString());
|
||||||
}
|
}
|
||||||
|
});
|
||||||
@Override
|
|
||||||
public void onButtonClicked(String text) {
|
}
|
||||||
|
|
||||||
switch (text) {
|
@Override
|
||||||
case "downloadFile":
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 23)
|
MenuInflater inflater = getMenuInflater();
|
||||||
{
|
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
||||||
if (checkPermission())
|
return true;
|
||||||
{
|
}
|
||||||
requestFileDownload();
|
|
||||||
}
|
@Override
|
||||||
else {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
requestPermission();
|
|
||||||
}
|
int id = item.getItemId();
|
||||||
}
|
|
||||||
else
|
switch(id) {
|
||||||
{
|
case android.R.id.home:
|
||||||
requestFileDownload();
|
finish();
|
||||||
}
|
return true;
|
||||||
break;
|
case R.id.genericMenu:
|
||||||
|
BottomSheetFileViewerFragment bottomSheet = new BottomSheetFileViewerFragment();
|
||||||
}
|
bottomSheet.show(getSupportFragmentManager(), "fileViewerBottomSheet");
|
||||||
|
return true;
|
||||||
}
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
private void requestFileDownload() {
|
}
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(getApplicationContext());
|
}
|
||||||
|
|
||||||
if(!tinyDb.getString("downloadFileContents").isEmpty()) {
|
@Override
|
||||||
|
public void onButtonClicked(String text) {
|
||||||
File outputFileName = new File(tinyDb.getString("downloadFileName"));
|
|
||||||
final File downloadFilePath = new File(Environment.getExternalStorageDirectory().getPath() + "/Download/" + outputFileName.getName());
|
switch(text) {
|
||||||
|
case "downloadFile":
|
||||||
byte[] pdfAsBytes = Base64.decode(tinyDb.getString("downloadFileContents"), 0);
|
|
||||||
FileOutputStream fileOutputStream = null;
|
if(Build.VERSION.SDK_INT >= 23) {
|
||||||
|
if(checkPermission()) {
|
||||||
try {
|
requestFileDownload();
|
||||||
|
}
|
||||||
fileOutputStream = new FileOutputStream(downloadFilePath, false);
|
else {
|
||||||
Objects.requireNonNull(fileOutputStream).write(pdfAsBytes);
|
requestPermission();
|
||||||
fileOutputStream.flush();
|
}
|
||||||
fileOutputStream.close();
|
}
|
||||||
Toasty.info(getApplicationContext(), getString(R.string.downloadFileSaved));
|
else {
|
||||||
|
requestFileDownload();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
break;
|
||||||
Log.e("errorFileDownloading", Objects.requireNonNull(e.getMessage()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
Toasty.error(getApplicationContext(), getString(R.string.waitLoadingDownloadFile));
|
private void requestFileDownload() {
|
||||||
}
|
|
||||||
|
final TinyDB tinyDb = new TinyDB(getApplicationContext());
|
||||||
}
|
|
||||||
|
if(!tinyDb.getString("downloadFileContents").isEmpty()) {
|
||||||
private boolean checkPermission() {
|
|
||||||
int result = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
File outputFileName = new File(tinyDb.getString("downloadFileName"));
|
||||||
return result == PackageManager.PERMISSION_GRANTED;
|
final File downloadFilePath = new File(Environment.getExternalStorageDirectory().getPath() + "/Download/" + outputFileName.getName());
|
||||||
}
|
|
||||||
|
byte[] pdfAsBytes = Base64.decode(tinyDb.getString("downloadFileContents"), 0);
|
||||||
private void requestPermission() {
|
FileOutputStream fileOutputStream = null;
|
||||||
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
|
|
||||||
}
|
try {
|
||||||
|
|
||||||
@Override
|
fileOutputStream = new FileOutputStream(downloadFilePath, false);
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
Objects.requireNonNull(fileOutputStream).write(pdfAsBytes);
|
||||||
switch (requestCode) {
|
fileOutputStream.flush();
|
||||||
case PERMISSION_REQUEST_CODE:
|
fileOutputStream.close();
|
||||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
Toasty.info(getApplicationContext(), getString(R.string.downloadFileSaved));
|
||||||
Log.i("PermissionsCheck", "Permission Granted");
|
|
||||||
}
|
}
|
||||||
else {
|
catch(IOException e) {
|
||||||
Log.e("PermissionsCheck", "Permission Denied");
|
Log.e("errorFileDownloading", Objects.requireNonNull(e.getMessage()));
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
|
Toasty.error(getApplicationContext(), getString(R.string.waitLoadingDownloadFile));
|
||||||
private void initCloseListener() {
|
}
|
||||||
onClickListener = new View.OnClickListener() {
|
|
||||||
@Override
|
}
|
||||||
public void onClick(View view) {
|
|
||||||
getIntent().removeExtra("singleFileName");
|
private boolean checkPermission() {
|
||||||
finish();
|
|
||||||
}
|
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) {
|
||||||
|
case PERMISSION_REQUEST_CODE:
|
||||||
|
if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
Log.i("PermissionsCheck", "Permission Granted");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log.e("PermissionsCheck", "Permission Denied");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 String[] themeList = {"Dark", "Light", "Auto (Day/Night)"};
|
||||||
private static int themeSelectedChoice = 0;
|
private static int themeSelectedChoice = 0;
|
||||||
|
|
||||||
|
private static String[] fileveiwerSourceCodeThemesList = {"Sublime", "Arduino Light", "Github", "Far ", "Ir Black", "Android Studio"};
|
||||||
|
private static int fileveiwerSourceCodeThemesSelectedChoice = 0;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
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 homeScreenSelected = v.findViewById(R.id.homeScreenSelected); // setter for home screen
|
||||||
final TextView customFontSelected = v.findViewById(R.id.customFontSelected); // setter for custom font
|
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 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 langFrame = v.findViewById(R.id.langFrame);
|
||||||
LinearLayout timeFrame = v.findViewById(R.id.timeFrame);
|
LinearLayout timeFrame = v.findViewById(R.id.timeFrame);
|
||||||
@ -68,6 +72,7 @@ public class SettingsFragment extends Fragment {
|
|||||||
LinearLayout customFontFrame = v.findViewById(R.id.customFontFrame);
|
LinearLayout customFontFrame = v.findViewById(R.id.customFontFrame);
|
||||||
LinearLayout themeFrame = v.findViewById(R.id.themeSelectionFrame);
|
LinearLayout themeFrame = v.findViewById(R.id.themeSelectionFrame);
|
||||||
LinearLayout certsFrame = v.findViewById(R.id.certsFrame);
|
LinearLayout certsFrame = v.findViewById(R.id.certsFrame);
|
||||||
|
LinearLayout sourceCodeThemeFrame = v.findViewById(R.id.sourceCodeThemeFrame);
|
||||||
|
|
||||||
Switch counterBadgesSwitch = v.findViewById(R.id.switchCounterBadge);
|
Switch counterBadgesSwitch = v.findViewById(R.id.switchCounterBadge);
|
||||||
Switch pdfModeSwitch = v.findViewById(R.id.switchPdfMode);
|
Switch pdfModeSwitch = v.findViewById(R.id.switchPdfMode);
|
||||||
@ -107,6 +112,10 @@ public class SettingsFragment extends Fragment {
|
|||||||
themeSelected.setText(tinyDb.getString("themeStr"));
|
themeSelected.setText(tinyDb.getString("themeStr"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!tinyDb.getString("fileviewerSourceCodeThemeStr").isEmpty()) {
|
||||||
|
fileveiwerSourceCodeThemesSelected.setText(tinyDb.getString("fileviewerSourceCodeThemeStr"));
|
||||||
|
}
|
||||||
|
|
||||||
if(langSelectedChoice == 0) {
|
if(langSelectedChoice == 0) {
|
||||||
langSelectedChoice = tinyDb.getInt("langId");
|
langSelectedChoice = tinyDb.getInt("langId");
|
||||||
}
|
}
|
||||||
@ -131,6 +140,10 @@ public class SettingsFragment extends Fragment {
|
|||||||
themeSelectedChoice = tinyDb.getInt("themeId");
|
themeSelectedChoice = tinyDb.getInt("themeId");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(fileveiwerSourceCodeThemesSelectedChoice == 0) {
|
||||||
|
fileveiwerSourceCodeThemesSelectedChoice = tinyDb.getInt("fileviewerThemeId");
|
||||||
|
}
|
||||||
|
|
||||||
if(tinyDb.getBoolean("enableCounterBadges")) {
|
if(tinyDb.getBoolean("enableCounterBadges")) {
|
||||||
counterBadgesSwitch.setChecked(true);
|
counterBadgesSwitch.setChecked(true);
|
||||||
}
|
}
|
||||||
@ -145,6 +158,38 @@ public class SettingsFragment extends Fragment {
|
|||||||
pdfModeSwitch.setChecked(false);
|
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
|
// certs deletion
|
||||||
certsFrame.setOnClickListener(v1 -> {
|
certsFrame.setOnClickListener(v1 -> {
|
||||||
|
|
||||||
|
@ -49,4 +49,34 @@
|
|||||||
|
|
||||||
</RelativeLayout>
|
</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>
|
</LinearLayout>
|
@ -279,6 +279,9 @@
|
|||||||
<string name="settingsPdfModeHeaderText">PDF Night Mode</string>
|
<string name="settingsPdfModeHeaderText">PDF Night Mode</string>
|
||||||
<string name="fileViewerHeader">File Viewer</string>
|
<string name="fileViewerHeader">File Viewer</string>
|
||||||
<string name="settingsCounterBadges">Counter Badges</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 -->
|
<!-- settings -->
|
||||||
|
|
||||||
<string name="noMoreData">No more data available</string>
|
<string name="noMoreData">No more data available</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user