Skip to content

Commit

Permalink
Changed dismiss button of hidden dialog to be "OK" (#1719)
Browse files Browse the repository at this point in the history
Changed dismiss button of hidden dialog to be "OK"
  • Loading branch information
EmmanuelMess authored Nov 27, 2019
2 parents 80de2cf + 8a99dca commit 660a8be
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 62 deletions.
97 changes: 59 additions & 38 deletions app/src/main/java/com/amaze/filemanager/adapters/HiddenAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;
import com.afollestad.materialdialogs.MaterialDialog;
import com.amaze.filemanager.R;
import com.amaze.filemanager.activities.MainActivity;
Expand All @@ -19,81 +21,100 @@
import com.amaze.filemanager.utils.DataUtils;
import com.amaze.filemanager.utils.OpenMode;
import com.amaze.filemanager.utils.files.FileUtils;

import java.io.File;
import java.util.ArrayList;


/**
* Created by Arpit on 16-11-2014 edited by Emmanuel Messulam <[email protected]>
* This Adapter contains all logic related to showing the list of hidden files.
*
* Created by Arpit on 16-11-2014 edited by Emmanuel Messulam <[email protected]>.
*
* @author Bowie Chen on 2019-10-26.
* @see com.amaze.filemanager.adapters.holders.HiddenViewHolder
*/
public class HiddenAdapter extends RecyclerView.Adapter<HiddenViewHolder> {
private static final String TAG = "HiddenAdapter";

private SharedPreferences sharedPrefs;
private MainFragment context;
private Context c;
private ArrayList<HybridFile> items;
private MainFragment mainFragment;
private Context context;
private ArrayList<HybridFile> hiddenFiles;
private MaterialDialog materialDialog;
private boolean hide;
private DataUtils dataUtils = DataUtils.getInstance();

public HiddenAdapter(Context context, MainFragment mainFrag, SharedPreferences sharedPreferences,
ArrayList<HybridFile> items, MaterialDialog materialDialog, boolean hide) {
this.c = context;
this.context = mainFrag;
ArrayList<HybridFile> hiddenFiles, MaterialDialog materialDialog, boolean hide) {
this.context = context;
this.mainFragment = mainFrag;
sharedPrefs = sharedPreferences;
this.items = new ArrayList<>(items);
this.hiddenFiles = new ArrayList<>(hiddenFiles);
this.hide = hide;
this.materialDialog = materialDialog;
}

@Override
public HiddenViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater mInflater = (LayoutInflater) c
@NonNull
public HiddenViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View view = mInflater.inflate(R.layout.bookmarkrow, parent, false);

return new HiddenViewHolder(view);
}

@Override
@SuppressWarnings("unchecked") // suppress varargs warnings
public void onBindViewHolder(HiddenViewHolder holder, int position) {
HybridFile file = items.get(position);
HybridFile file = hiddenFiles.get(position);

holder.txtTitle.setText(file.getName());
String a = file.getReadablePath(file.getPath());
holder.txtDesc.setText(a);
holder.textTitle.setText(file.getName(context));
holder.textDescription.setText(file.getReadablePath(file.getPath()));

if (hide) {
holder.image.setVisibility(View.GONE);
holder.deleteButton.setVisibility(View.GONE);
}

// TODO: move the listeners to the constructor
holder.image.setOnClickListener(view -> {
if (!file.isSmb() && file.isDirectory()) {
ArrayList<HybridFileParcelable> a1 = new ArrayList<>();
HybridFileParcelable baseFile = new HybridFileParcelable(items.get(position).getPath() + "/.nomedia");
baseFile.setMode(OpenMode.FILE);
a1.add(baseFile);
new DeleteTask(c).execute((a1));
holder.deleteButton.setOnClickListener(view -> {
// if the user taps on the delete button, un-hide the file.
// TODO: the "hide files" feature just hide files from view in Amaze and not create .nomedia

if (!file.isSmb() && file.isDirectory(context)) {
HybridFileParcelable nomediaFile = new HybridFileParcelable(
hiddenFiles.get(position).getPath() + "/" + FileUtils.NOMEDIA_FILE);
nomediaFile.setMode(OpenMode.FILE);

ArrayList<HybridFileParcelable> filesToDelete = new ArrayList<>();
filesToDelete.add(nomediaFile);

DeleteTask task = new DeleteTask(context);
task.execute(filesToDelete);
}
dataUtils.removeHiddenFile(items.get(position).getPath());
items.remove(items.get(position));

dataUtils.removeHiddenFile(hiddenFiles.get(position).getPath());
hiddenFiles.remove(hiddenFiles.get(position));
notifyDataSetChanged();
});
holder.row.setOnClickListener(view -> {
// if the user taps on the hidden file, take the user there.
materialDialog.dismiss();
new Thread(() -> {
if (file.isDirectory()) {
context.getActivity().runOnUiThread(() -> {
context.loadlist(file.getPath(), false, OpenMode.UNKNOWN);
});
FragmentActivity fragmentActivity = mainFragment.getActivity();
if (fragmentActivity == null) {
// nullity check
return;
}

if (file.isDirectory(context)) {
fragmentActivity.runOnUiThread(
() -> mainFragment.loadlist(file.getPath(), false, OpenMode.UNKNOWN));
} else if (!file.isSmb()) {
fragmentActivity.runOnUiThread(() -> FileUtils
.openFile(new File(file.getPath()), (MainActivity) fragmentActivity,
sharedPrefs));
} else {
if (!file.isSmb()) {
context.getActivity().runOnUiThread(() -> {
FileUtils.openFile(new File(file.getPath()), (MainActivity) context.getActivity(), sharedPrefs);
});
}
Log.w(TAG, "User tapped on a directory but conditions not met; nothing is done.");
}
}).start();
});
Expand All @@ -110,7 +131,7 @@ public long getItemId(int position) {

@Override
public int getItemCount() {
return items.size();
return hiddenFiles.size();
}

}
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
package com.amaze.filemanager.adapters.holders;

import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;
import com.amaze.filemanager.R;

/**
* @author Emmanuel
* on 20/11/2017, at 18:38.
* This is the ViewHolder that formats the hidden files as defined in bookmarkrow.xml.
*
* @author Emmanuel on 20/11/2017, at 18:38.
* @author Bowie Chen on 2019-10-26.
* @see com.amaze.filemanager.adapters.HiddenAdapter
*/

public class HiddenViewHolder extends RecyclerView.ViewHolder {
public final ImageButton image;
public final TextView txtTitle;
public final TextView txtDesc;

public final ImageButton deleteButton;
public final TextView textTitle;
public final TextView textDescription;
public final LinearLayout row;

public HiddenViewHolder(View view) {
super(view);

txtTitle = view.findViewById(R.id.text1);
image = view.findViewById(R.id.delete_button);
txtDesc = view.findViewById(R.id.text2);
textTitle = view.findViewById(R.id.filename);
deleteButton = view.findViewById(R.id.delete_button);
textDescription = view.findViewById(R.id.file_path);
row = view.findViewById(R.id.bookmarkrow);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,6 @@ public static void showHistoryDialog(final DataUtils dataUtils, SharedPreference
a.onNegative((dialog, which) -> dataUtils.clearHistory());
a.theme(appTheme.getMaterialDialogTheme());

a.autoDismiss(true);
HiddenAdapter adapter = new HiddenAdapter(m.getActivity(), m, sharedPrefs,
toHybridFileArrayList(dataUtils.getHistory()), null, true);
a.adapter(adapter, null);
Expand All @@ -1106,20 +1105,24 @@ public static void showHistoryDialog(final DataUtils dataUtils, SharedPreference

public static void showHiddenDialog(DataUtils dataUtils, SharedPreferences sharedPrefs,
final MainFragment m, AppTheme appTheme) {
if (m == null || m.getActivity() == null) {
return;
}

int accentColor = m.getMainActivity().getAccent();
final MaterialDialog.Builder a = new MaterialDialog.Builder(m.getActivity());
a.positiveText(R.string.cancel);
a.positiveColor(accentColor);
a.title(R.string.hiddenfiles);
a.theme(appTheme.getMaterialDialogTheme());
a.autoDismiss(true);
final MaterialDialog.Builder builder = new MaterialDialog.Builder(m.getActivity());
builder.positiveText(R.string.close);
builder.positiveColor(accentColor);
builder.title(R.string.hiddenfiles);
builder.theme(appTheme.getMaterialDialogTheme());
builder.autoDismiss(true);
HiddenAdapter adapter = new HiddenAdapter(m.getActivity(), m, sharedPrefs,
FileUtils.toHybridFileConcurrentRadixTree(dataUtils.getHiddenFiles()), null, false);
a.adapter(adapter, null);
a.dividerColor(Color.GRAY);
MaterialDialog x = a.build();
adapter.updateDialog(x);
x.show();
builder.adapter(adapter, null);
builder.dividerColor(Color.GRAY);
MaterialDialog materialDialog = builder.build();
adapter.updateDialog(materialDialog);
materialDialog.show();

}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/bookmarkrow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
android:orientation="vertical"
android:paddingLeft="10dip">
<TextView
android:id="@+id/text1"
android:id="@+id/filename"
style="@style/Base.TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:paddingLeft="?android:listPreferredItemPaddingLeft" />

<TextView
android:id="@+id/text2"
android:id="@+id/file_path"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_weight="1"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -602,4 +602,5 @@
<string name="archive_password_prompt">請輸入壓縮檔的密碼。</string>
<string name="cannot_extract_archive">不能開啟壓縮檔 \"%s\": %s</string>
<string name="archive_unsupported_or_corrupt">不能開啟壓縮檔 \"%s\"。可能是程式庫不支援此壓縮檔,或者壓縮檔真的壞掉了。</string>
<string name="close">關閉</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@
<string name="empty_string" translatable="false" />
<string name="cannot_extract_archive">Cannot extract archive \"%s\": %s</string>
<string name="archive_unsupported_or_corrupt">Cannot open archive \"%s\". Either we cannot open the archive, or the archive was damaged.</string>
<string name="close">Close</string>
<string name="bookmark_exists">Bookmark exists</string>
<string name="hide_media">Hide from media browsers</string>
</resources>
Expand Down

0 comments on commit 660a8be

Please sign in to comment.