Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
android:theme="@style/AppTheme">
<activity
android:name=".SettingsActivity"
android:parentActivityName=".MainActivity"
android:label="@string/title_activity_settings"></activity>
<activity android:name=".MultiPageActivity" />
<activity android:name=".IntroActivity" />
Expand Down
23 changes: 20 additions & 3 deletions app/src/main/java/com/babanomania/pdfscanner/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.icu.text.SimpleDateFormat;
Expand All @@ -21,6 +22,7 @@

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
Expand Down Expand Up @@ -71,6 +73,17 @@ public MainActivity() {

@Override
protected void onCreate(Bundle savedInstanceState) {

SharedPreferences prefs = getSharedPreferences("save", MODE_PRIVATE);
boolean isDark = prefs.getBoolean("DarkMode", true);

if(isDark){
setTheme(R.style.AppThemeDark);
}
else {
setTheme(R.style.AppTheme);
}

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Expand All @@ -92,7 +105,7 @@ protected void onCreate(Bundle savedInstanceState) {

viewModel = ViewModelProviders.of(this).get(DocumentViewModel.class);

fileAdapter = new FLAdapter( viewModel, this);
fileAdapter = new FLAdapter( viewModel, this, isDark);
recyclerView.setAdapter( fileAdapter );

liveData = viewModel.getAllDocuments();
Expand Down Expand Up @@ -166,6 +179,8 @@ public void openCamera(View v){
// }

private void saveBitmap( final Bitmap bitmap, final boolean addMore ){
SharedPreferences prefs = getSharedPreferences("save", MODE_PRIVATE);
boolean isDark = prefs.getBoolean("DarkMode", true);

final String baseDirectory = getApplicationContext().getString( addMore ? R.string.base_staging_path : R.string.base_storage_path);
final File sd = Environment.getExternalStorageDirectory();
Expand Down Expand Up @@ -195,7 +210,7 @@ public void write(FileOutputStream out) {

} else {

DialogUtil.askUserFilaname( c, null, null, new DialogUtilCallback() {
DialogUtil.askUserFilaname( c, null, null, isDark, new DialogUtilCallback() {

@Override
public void onSave(String textValue, String category) {
Expand Down Expand Up @@ -262,6 +277,8 @@ public void write(FileOutputStream out) {
}

private void savePdf() {
SharedPreferences prefs = getSharedPreferences("save", MODE_PRIVATE);
boolean isDark = prefs.getBoolean("DarkMode", true);

final String baseDirectory = getApplicationContext().getString(R.string.base_storage_path);
final File sd = Environment.getExternalStorageDirectory();
Expand All @@ -270,7 +287,7 @@ private void savePdf() {
final String timestamp = simpleDateFormat.format(new Date());


DialogUtil.askUserFilaname(c, null, null, new DialogUtilCallback() {
DialogUtil.askUserFilaname(c, null, null, isDark, new DialogUtilCallback() {

@Override
public void onSave(String textValue, String category) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.DataSetObserver;
import android.graphics.Bitmap;
Expand Down Expand Up @@ -48,6 +49,17 @@ public class MultiPageActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

SharedPreferences prefs = getSharedPreferences("save", MODE_PRIVATE);
boolean isDark = prefs.getBoolean("DarkMode", true);

if(isDark){
setTheme(R.style.AppThemeDark);
}
else {
setTheme(R.style.AppTheme);
}

setContentView(R.layout.activity_multi_page);

setTitle( getResources().getString(R.string.multi_page_title) );
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/babanomania/pdfscanner/OCRActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.pdf.PdfRenderer;
import android.os.AsyncTask;
Expand Down Expand Up @@ -33,6 +34,17 @@ public class OCRActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

SharedPreferences prefs = getSharedPreferences("save", MODE_PRIVATE);
boolean isDark = prefs.getBoolean("DarkMode", true);

if(isDark){
setTheme(R.style.AppThemeDark);
}
else {
setTheme(R.style.AppTheme);
}

setContentView(R.layout.activity_ocr);

RelativeLayout relativeLayout = findViewById(R.id.rl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.SearchManager;
import android.app.SearchableInfo;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -11,6 +12,7 @@

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.SearchView;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
Expand All @@ -33,6 +35,20 @@ public class SearchableActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {


SharedPreferences prefs = getSharedPreferences("save", MODE_PRIVATE);
boolean isDark = prefs.getBoolean("DarkMode", true);

if(isDark){
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.AppThemeSearchDark);
}
else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
setTheme(R.style.AppThemeSearch);
}

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_searchable);

Expand All @@ -44,7 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {

DocumentViewModel viewModel = ViewModelProviders.of(this).get(DocumentViewModel.class);

final FLAdapter fileAdapter = new FLAdapter( viewModel, this);
final FLAdapter fileAdapter = new FLAdapter( viewModel, this, isDark);
recyclerView.setAdapter( fileAdapter );

this.emptyLayout = findViewById(R.id.empty_search_list);
Expand Down Expand Up @@ -77,6 +93,9 @@ public void onChanged(@Nullable List<Document> documents) {
@Override
public boolean onCreateOptionsMenu(Menu menu) {

SharedPreferences prefs = getSharedPreferences("save", MODE_PRIVATE);
final boolean isDark = prefs.getBoolean("DarkMode", true);

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getMenuInflater().inflate(R.menu.searchview_menu, menu);

Expand All @@ -100,23 +119,23 @@ public boolean onQueryTextSubmit(String query) {

@Override
public boolean onQueryTextChange(String newText) {
doMySearch( newText );
doMySearch( newText, isDark);
return false;
}
});

return true;
}

public void doMySearch( String query ){
public void doMySearch( String query, boolean isDark ){

this.recyclerView = findViewById(R.id.rwSearch);

UIUtil.setLightNavigationBar( recyclerView, this );

DocumentViewModel viewModel = ViewModelProviders.of(this).get(DocumentViewModel.class);

final FLAdapter fileAdapter = new FLAdapter( viewModel, this);
final FLAdapter fileAdapter = new FLAdapter( viewModel, this, isDark);
recyclerView.setAdapter( fileAdapter );

viewModel.search( '%' + query + '%').observe(this, new Observer<List<Document>>() {
Expand Down
74 changes: 74 additions & 0 deletions app/src/main/java/com/babanomania/pdfscanner/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
package com.babanomania.pdfscanner;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Toast;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.SwitchCompat;
import androidx.preference.PreferenceFragmentCompat;

import com.babanomania.pdfscanner.persistance.DocumentDatabase;

public class SettingsActivity extends AppCompatActivity {

SwitchCompat switchCompat;

@Override
protected void onCreate(Bundle savedInstanceState) {

DocumentDatabase.getInstance(getApplicationContext());
if (loadState()) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.AppThemeDark);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
setTheme(R.style.AppTheme);
}


super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);

Expand All @@ -22,8 +43,61 @@ protected void onCreate(Bundle savedInstanceState) {
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}

switchCompat = findViewById(R.id.bt_switch);

SharedPreferences sharedPreferences = getSharedPreferences("save", MODE_PRIVATE);
switchCompat.setChecked(sharedPreferences.getBoolean("DarkMode", true));

switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
saveSwitchState(true);
switchCompat.setChecked(true);
}
else{
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
saveSwitchState(false);
switchCompat.setChecked(false);
}
}
});
//
// switchCompat.setOnCheckedChangeListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// if (switchCompat.isChecked()){
// AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
// saveSwitchState(true);
// switchCompat.setChecked(true);
// }
// else {
// AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
// saveSwitchState(false);
// switchCompat.setChecked(false);
// }
// }
// });
}


public void saveSwitchState(Boolean state){
SharedPreferences sharedPreferences = getSharedPreferences("save", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("DarkMode", state);
editor.apply();
}

private Boolean loadState(){
SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("save", MODE_PRIVATE);
return sharedPreferences.getBoolean("DarkMode", false);
}




public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class FLAdapter extends RecyclerView.Adapter<FLViewHolder> {
public boolean multiSelect = false;
private List<Document> documentList = new ArrayList<>();
public List<Document> selectedItems = new ArrayList<>();
public boolean isDark;

private DocumentViewModel viewModel;

Expand Down Expand Up @@ -104,7 +105,7 @@ public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
case R.id.menu_edit:

final Document docToRename = selectedItems.get(0);
DialogUtil.askUserFilaname(context, docToRename.getName(), docToRename.getCategory(), new DialogUtilCallback() {
DialogUtil.askUserFilaname(context, docToRename.getName(), docToRename.getCategory(),isDark, new DialogUtilCallback() {

@Override
public void onSave(String textValue, String category) {
Expand Down Expand Up @@ -163,9 +164,10 @@ public void onDestroyActionMode(ActionMode mode) {
}
};

public FLAdapter( DocumentViewModel viewModel, Context context ){
public FLAdapter( DocumentViewModel viewModel, Context context, boolean isDark ){
this.viewModel = viewModel;
this.context = context;
this.isDark = isDark;
}

public void setData(List<Document> documents){
Expand All @@ -180,7 +182,7 @@ public FLViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
View listItem = layoutInflater.inflate( R.layout.file_item_view, viewGroup, false );
FLViewHolder viewHolder = new FLViewHolder(listItem, actionModeCallbacks, this );
FLViewHolder viewHolder = new FLViewHolder(listItem, actionModeCallbacks, this, isDark );

return viewHolder;
}
Expand Down
Loading