Skip to content

Commit

Permalink
Removing ALL instance creation of Futils EXCEPT in BasicActivity.
Browse files Browse the repository at this point in the history
- BasicActivity implements UtilitiesProviderInterface which is used to inject application-wide properties (currently only Futils but that will change soon) and is the ONLY place where Futils is intantiated
- For methods used in only one class, the helper method has been moved to the class
- For methods that could be put static: added static modifier so no instance of Futils is needed
- For Futils::getString: replaced by getResources().getString as Futils::getString was just a shortcut adding an 'unwanted' dependency
- Imports cleaning
  • Loading branch information
Rémi Piotaix committed Oct 17, 2016
1 parent 8e68890 commit 185b497
Show file tree
Hide file tree
Showing 40 changed files with 352 additions and 342 deletions.
49 changes: 25 additions & 24 deletions src/fdroid/java/com/amaze/filemanager/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public void onTick(long l) {

@Override
public void onFinish() {
utils.crossfadeInverse(buttons, pathbar);
getFutils().crossfadeInverse(buttons, pathbar);
}
};
path = getIntent().getStringExtra("path");
Expand All @@ -297,12 +297,12 @@ public void onFinish() {

// file picker intent
mReturnIntent = true;
Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
Toast.makeText(this, getResources().getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
} else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) {
// ringtone picker intent
mReturnIntent = true;
mRingtonePickerIntent = true;
Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
Toast.makeText(this, getResources().getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
} else if (intent.getAction().equals(Intent.ACTION_VIEW)) {

// zip viewer intent
Expand Down Expand Up @@ -349,7 +349,7 @@ public void onFinish() {
goToMain(path);
else {
goToMain("");
utils.openFile(new File(path), this);
getFutils().openFile(new File(path), this);
}
} else {
goToMain("");
Expand Down Expand Up @@ -480,7 +480,7 @@ public List<String> getStorageDirectories() {
String strings[] = FileUtil.getExtSdCardPathsForActivity(this);
for (String s : strings) {
File f = new File(s);
if (!rv.contains(s) && utils.canListFiles(f))
if (!rv.contains(s) && Futils.canListFiles(f))
rv.add(s);
}
}
Expand Down Expand Up @@ -513,7 +513,7 @@ void onbackpressed() {
} else if (name.contains("TabFragment")) {
if (floatingActionButton.isOpened()) {
floatingActionButton.close(true);
utils.revealShow(findViewById(R.id.fab_bg), false);
getFutils().revealShow(findViewById(R.id.fab_bg), false);
} else {
TabFragment tabFragment = ((TabFragment) getSupportFragmentManager().findFragmentById(R.id.content_frame));
Fragment fragment1 = tabFragment.getTab();
Expand Down Expand Up @@ -570,7 +570,7 @@ public void exit() {
}
} else {
this.backPressedToExitOnce = true;
showToast(utils.getString(this, R.string.pressagain));
showToast(getResources().getString(R.string.pressagain));
new Handler().postDelayed(new Runnable() {

@Override
Expand Down Expand Up @@ -661,7 +661,7 @@ public void updateDrawer() {
list.add(new EntryItem(getResources().getString(R.string.documents), "3", ContextCompat.getDrawable(this, R.drawable.ic_doc_doc_am)));
list.add(new EntryItem(getResources().getString(R.string.apks), "4", ContextCompat.getDrawable(this, R.drawable.ic_doc_apk_grid)));
DataUtils.setList(list);
adapter = new DrawerAdapter(this, list, MainActivity.this, Sp);
adapter = new DrawerAdapter(this, this, list, MainActivity.this, Sp);
mDrawerList.setAdapter(adapter);
}

Expand Down Expand Up @@ -928,7 +928,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
case R.id.history:
if (ma != null)
utils.showHistoryDialog(ma);
getFutils().showHistoryDialog(ma);
break;
case R.id.sethome:
if (ma == null) return super.onOptionsItemSelected(item);
Expand All @@ -937,7 +937,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
Toast.makeText(mainActivity, R.string.not_allowed, Toast.LENGTH_SHORT).show();
break;
}
final MaterialDialog b = utils.showBasicDialog(mainActivity, BaseActivity.accentSkin, theme1,
final MaterialDialog b = Futils.showBasicDialog(mainActivity, BaseActivity.accentSkin, theme1,
new String[]{getResources().getString(R.string.questionset),
getResources().getString(R.string.setashome), getResources().getString(R.string.yes), getResources().getString(R.string.no), null});
b.getActionButton(DialogAction.POSITIVE).setOnClickListener(new View.OnClickListener() {
Expand All @@ -957,12 +957,12 @@ public void onClick(View v) {
case R.id.item10:
Fragment fragment = getDFragment();
if (fragment.getClass().getName().contains("AppsList"))
utils.showSortDialog((AppsList) fragment);
getFutils().showSortDialog((AppsList) fragment);

break;
case R.id.sortby:
if (ma != null)
utils.showSortDialog(ma);
getFutils().showSortDialog(ma);
break;
case R.id.dsort:
if (ma == null) return super.onOptionsItemSelected(item);
Expand All @@ -982,7 +982,7 @@ public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequ
a.build().show();
break;
case R.id.hiddenitems:
utils.showHiddenDialog(ma);
getFutils().showHiddenDialog(ma);
break;
case R.id.view:
if (ma.IS_LIST) {
Expand Down Expand Up @@ -1052,7 +1052,7 @@ void revealSearchView() {
animator = new ObjectAnimator().ofFloat(searchViewLayout, "alpha", 0f, 1f);
}

utils.revealShow(mFabBackground, true);
getFutils().revealShow(mFabBackground, true);

animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(600);
Expand Down Expand Up @@ -1103,7 +1103,7 @@ public void hideSearchView() {
}

// removing background fade view
utils.revealShow(mFabBackground, false);
getFutils().revealShow(mFabBackground, false);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(600);
animator.start();
Expand Down Expand Up @@ -1393,7 +1393,7 @@ public void refreshDrawer() {
list.add(new EntryItem(getResources().getString(R.string.documents), "3", ContextCompat.getDrawable(this, R.drawable.ic_doc_doc_am)));
list.add(new EntryItem(getResources().getString(R.string.apks), "4", ContextCompat.getDrawable(this, R.drawable.ic_doc_apk_grid)));
DataUtils.setList(list);
adapter = new DrawerAdapter(con, list, MainActivity.this, Sp);
adapter = new DrawerAdapter(con, this, list, MainActivity.this, Sp);
mDrawerList.setAdapter(adapter);

}
Expand Down Expand Up @@ -1486,7 +1486,7 @@ public void bbar(final Main main) {
buttons.removeAllViews();
buttons.setMinimumHeight(pathbar.getHeight());
Drawable arrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_holo_dark);
Bundle b = utils.getPaths(text, this);
Bundle b = getFutils().getPaths(text, this);
ArrayList<String> names = b.getStringArrayList("names");
ArrayList<String> rnames = new ArrayList<String>();

Expand Down Expand Up @@ -1698,7 +1698,7 @@ public boolean onLongClick(View v) {
@Override
public void onClick(View view) {
floatingActionButton.close(true);
utils.revealShow(view, false);
getFutils().revealShow(view, false);
if (isSearchViewEnabled) hideSearchView();
}
});
Expand Down Expand Up @@ -1875,6 +1875,7 @@ void initialiseFab() {
floatingActionButton = (FloatingActionMenu) findViewById(R.id.menu);
floatingActionButton.setMenuButtonColorNormal(Color.parseColor(BaseActivity.accentSkin));
floatingActionButton.setMenuButtonColorPressed(fabSkinPressed);
final Futils utils = getFutils();

//if (theme1 == 1) floatingActionButton.setMen
floatingActionButton.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() {
Expand Down Expand Up @@ -2187,7 +2188,7 @@ public void onClick(View view) {
Main m = ((Main) getFragment().getTab());
if (m.openMode == 0) {
bbar(m);
utils.crossfade(buttons,pathbar);
getFutils().crossfade(buttons,pathbar);
timer.cancel();
timer.start();
}
Expand All @@ -2199,7 +2200,7 @@ public void onClick(View view) {
Main m = ((Main) getFragment().getTab());
if (m.openMode == 0) {
bbar(m);
utils.crossfade(buttons,pathbar);
getFutils().crossfade(buttons,pathbar);
timer.cancel();
timer.start();
}
Expand Down Expand Up @@ -2253,7 +2254,7 @@ void onDrawerClosed() {
HFile hFile = new HFile(HFile.UNKNOWN,pending_path);
hFile.generateMode(this);
if (hFile.isSimpleFile()) {
utils.openFile(new File(pending_path), mainActivity);
getFutils().openFile(new File(pending_path), mainActivity);
pending_path = null;
return;
}
Expand Down Expand Up @@ -2286,7 +2287,7 @@ public void onNewIntent(Intent i) {
Main m = ((Main) getFragment().getTab());
m.loadlist(path, false, 0);
} else goToMain(path);
} else utils.openFile(new File(path), mainActivity);
} else getFutils().openFile(new File(path), mainActivity);
} else if (i.getStringArrayListExtra("failedOps") != null) {
ArrayList<BaseFile> failedOps = i.getParcelableArrayListExtra("failedOps");
if (failedOps != null) {
Expand All @@ -2308,12 +2309,12 @@ public void onNewIntent(Intent i) {

// file picker intent
mReturnIntent = true;
Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
Toast.makeText(this, getResources().getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
} else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) {
// ringtone picker intent
mReturnIntent = true;
mRingtonePickerIntent = true;
Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
Toast.makeText(this, getResources().getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
} else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
// zip viewer intent
Uri uri = intent.getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.Toolbar;
import android.util.Log;
Expand All @@ -34,7 +33,7 @@
/**
* Created by vishal on 27/7/16.
*/
public class AboutActivity extends AppCompatActivity implements View.OnClickListener {
public class AboutActivity extends BasicActivity implements View.OnClickListener {

private static final int HEADER_HEIGHT = 1024;
private static final int HEADER_WIDTH = 500;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.afollestad.materialdialogs.DialogAction;
Expand All @@ -23,15 +22,14 @@
/**
* Created by arpitkh996 on 03-03-2016.
*/
public class BaseActivity extends AppCompatActivity {
public class BaseActivity extends BasicActivity {
public static int theme1;
public SharedPreferences Sp;

// Accent and Primary hex color string respectively
public static String accentSkin;
public static String skin, skinTwo;
public static boolean rootMode;
Futils utils = new Futils();
boolean checkStorage=true;
@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -95,7 +93,7 @@ void requestStoragePermission() {
// Provide an additional rationale to the user if the permission was not granted
// and the user would benefit from additional context for the use of the permission.
// For example, if the request has been denied previously.
final MaterialDialog materialDialog = utils.showBasicDialog(this,accentSkin,theme1, new String[]{getResources().getString(R.string.granttext), getResources().getString(R.string.grantper), getResources().getString(R.string.grant), getResources().getString(R.string.cancel), null});
final MaterialDialog materialDialog = Futils.showBasicDialog(this,accentSkin,theme1, new String[]{getResources().getString(R.string.granttext), getResources().getString(R.string.grantper), getResources().getString(R.string.grant), getResources().getString(R.string.cancel), null});
materialDialog.getActionButton(DialogAction.POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/amaze/filemanager/activities/BasicActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.amaze.filemanager.activities;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.amaze.filemanager.utils.Futils;
import com.amaze.filemanager.utils.UtilitiesProviderInterface;

/**
* Created by rpiotaix on 17/10/16.
*/
public class BasicActivity extends AppCompatActivity implements UtilitiesProviderInterface {
private Futils utils;

@Override
public Futils getFutils() {
return utils;
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
utils = new Futils();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.amaze.filemanager.activities;

import android.support.v7.app.AppCompatActivity;

/**
* Created by vishal on 7/8/16.
*/
public class ChangelogActivity extends AppCompatActivity {
public class ChangelogActivity extends BasicActivity {

private static final String URL_CHANGELOG = "https://api.github.com/repos/arpitkh96/AmazeFileManager/commits";
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

import org.sufficientlysecure.donations.DonationsFragment;

public class Preferences extends BaseActivity implements ActivityCompat.OnRequestPermissionsResultCallback {
public class Preferences extends BaseActivity implements ActivityCompat.OnRequestPermissionsResultCallback {
int select=0;
public int changed=0;
@Override
Expand Down
14 changes: 3 additions & 11 deletions src/main/java/com/amaze/filemanager/activities/TextReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
Expand All @@ -34,16 +33,12 @@
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.Spanned;
import android.text.TextWatcher;
import android.text.style.BackgroundColorSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewAnimationUtils;
Expand All @@ -64,7 +59,6 @@
import com.amaze.filemanager.filesystem.HFile;
import com.amaze.filemanager.filesystem.RootHelper;
import com.amaze.filemanager.services.asynctasks.SearchTextTask;
import com.amaze.filemanager.utils.Futils;
import com.amaze.filemanager.utils.MapEntry;
import com.amaze.filemanager.utils.PreferenceUtils;
import com.readystatesoftware.systembartint.SystemBarTintManager;
Expand All @@ -84,9 +78,7 @@
import java.util.Timer;
import java.util.TimerTask;

public class TextReader extends BaseActivity
implements TextWatcher, View.OnClickListener {

public class TextReader extends BaseActivity implements TextWatcher, View.OnClickListener {
String path;
Context c = this;
public EditText mInput, searchEditText;
Expand Down Expand Up @@ -464,12 +456,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
if(mFile.canRead()){
HFile hFile=new HFile(HFile.LOCAL_MODE,mFile.getPath());
hFile.generateMode(this);
utils.showProps(hFile, this, theme1);
getFutils().showProps(hFile, this, theme1);
}else Toast.makeText(this,R.string.not_allowed,Toast.LENGTH_SHORT).show();
break;
case R.id.openwith:
if(mFile.canRead()){
utils.openunknown(mFile, c, false);
getFutils().openunknown(mFile, c, false);
}else Toast.makeText(this,R.string.not_allowed,Toast.LENGTH_SHORT).show();
break;
case R.id.find:
Expand Down
Loading

0 comments on commit 185b497

Please sign in to comment.