-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: GauthamAsir <[email protected]>
- Loading branch information
GauthamAsir
committed
May 13, 2020
1 parent
eaddbf4
commit fbb01e2
Showing
9 changed files
with
447 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package a.gautham.neweditor; | ||
|
||
import android.os.Bundle; | ||
import android.os.Environment; | ||
import android.view.View; | ||
import android.widget.ListView; | ||
import android.widget.ProgressBar; | ||
import android.widget.TextView; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
import a.gautham.neweditor.helper.FileAdapter; | ||
import a.gautham.neweditor.helper.FileModel; | ||
|
||
public class EditedFiles extends AppCompatActivity { | ||
|
||
private ListView listView; | ||
private ProgressBar progressBar; | ||
private TextView no_files_tv; | ||
private List<FileModel> list = new ArrayList<>(); | ||
private File file; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_edited_files); | ||
|
||
listView = findViewById(R.id.listView); | ||
progressBar = findViewById(R.id.progressBar); | ||
no_files_tv = findViewById(R.id.no_files_tv); | ||
|
||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
|
||
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + | ||
"Pictures" + File.separator + "GMemes Creator"; | ||
|
||
file = new File(path); | ||
if (file.exists()) | ||
loadFiles(); | ||
else | ||
noFiles(); | ||
|
||
} | ||
|
||
private void loadFiles() { | ||
|
||
progressBar.setVisibility(View.VISIBLE); | ||
no_files_tv.setVisibility(View.GONE); | ||
listView.setVisibility(View.VISIBLE); | ||
|
||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
|
||
File[] values = file.listFiles(); | ||
list.clear(); | ||
|
||
if (values != null && values.length > 0) { | ||
|
||
Arrays.sort(values, new Comparator<File>() { | ||
@Override | ||
public int compare(File o1, File o2) { | ||
return Long.compare((o2).lastModified(), (o1).lastModified()); | ||
} | ||
}); | ||
for (File file1 : values) { | ||
if (!file1.isDirectory()) { | ||
FileModel fileModel = new FileModel( | ||
file1.getName(), | ||
FileUtils.byteCountToDisplaySize(file1.length()), | ||
file1); | ||
list.add(fileModel); | ||
} | ||
} | ||
|
||
runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
if (list.size() > 0) { | ||
FileAdapter fileAdapter = new FileAdapter(EditedFiles.this, list); | ||
listView.setAdapter(fileAdapter); | ||
progressBar.setVisibility(View.GONE); | ||
} else { | ||
noFiles(); | ||
} | ||
|
||
} | ||
}); | ||
|
||
} else { | ||
runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
noFiles(); | ||
} | ||
}); | ||
} | ||
|
||
} | ||
}).start(); | ||
|
||
} | ||
|
||
private void noFiles() { | ||
progressBar.setVisibility(View.GONE); | ||
no_files_tv.setVisibility(View.VISIBLE); | ||
listView.setVisibility(View.GONE); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
app/src/main/java/a/gautham/neweditor/helper/FileAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package a.gautham.neweditor.helper; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.content.pm.ResolveInfo; | ||
import android.net.Uri; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.core.content.FileProvider; | ||
|
||
import com.squareup.picasso.Picasso; | ||
|
||
import java.util.List; | ||
|
||
import a.gautham.neweditor.R; | ||
|
||
public class FileAdapter extends ArrayAdapter<FileModel> { | ||
|
||
public FileAdapter(@NonNull Context context, List<FileModel> arrayList) { | ||
super(context, 0, arrayList); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public View getView(final int position, @Nullable View convertView, @NonNull final ViewGroup parent) { | ||
|
||
final FileModel fileModel = getItem(position); | ||
|
||
if (convertView == null) { | ||
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.edited_items, parent, false); | ||
} | ||
|
||
ImageView file_thumbnail = convertView.findViewById(R.id.file_thumbnail); | ||
ImageView delete_file = convertView.findViewById(R.id.delete_file); | ||
ImageView share_file = convertView.findViewById(R.id.share_file); | ||
TextView file_name = convertView.findViewById(R.id.file_name); | ||
TextView file_size = convertView.findViewById(R.id.file_size); | ||
|
||
assert fileModel != null; | ||
Picasso.get().load(fileModel.getFile()).into(file_thumbnail); | ||
|
||
file_name.setText(fileModel.getName()); | ||
file_size.setText(fileModel.getSize()); | ||
|
||
delete_file.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
|
||
if (fileModel.getFile().exists() && fileModel.getFile().delete()) | ||
remove(fileModel); | ||
} | ||
}); | ||
|
||
share_file.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
|
||
Uri uri = FileProvider.getUriForFile( | ||
parent.getContext(), | ||
"a.gautham.neweditor.provider", | ||
fileModel.getFile()); | ||
|
||
Intent shareIntent = new Intent(Intent.ACTION_SEND); | ||
if (fileModel.getName().endsWith(".jpeg")) { | ||
shareIntent.setType("image/jpg"); | ||
} else { | ||
shareIntent.setType("image/png"); | ||
} | ||
shareIntent.putExtra(Intent.EXTRA_STREAM, uri); | ||
Intent chooser = Intent.createChooser(shareIntent, "Share image"); | ||
|
||
List<ResolveInfo> resInfoList = parent.getContext().getPackageManager() | ||
.queryIntentActivities(chooser, PackageManager.MATCH_DEFAULT_ONLY); | ||
|
||
for (ResolveInfo resolveInfo : resInfoList) { | ||
String packageName = resolveInfo.activityInfo.packageName; | ||
parent.getContext().grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||
} | ||
|
||
parent.getContext().startActivity(chooser); | ||
|
||
} | ||
}); | ||
|
||
return convertView; | ||
|
||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/a/gautham/neweditor/helper/FileModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package a.gautham.neweditor.helper; | ||
|
||
import java.io.File; | ||
|
||
public class FileModel { | ||
|
||
private String name; | ||
private String size; | ||
private File file; | ||
|
||
public FileModel(String name, String size, File file) { | ||
this.name = name; | ||
this.size = size; | ||
this.file = file; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getSize() { | ||
return size; | ||
} | ||
|
||
public void setSize(String size) { | ||
this.size = size; | ||
} | ||
|
||
public File getFile() { | ||
return file; | ||
} | ||
|
||
public void setFile(File file) { | ||
this.file = file; | ||
} | ||
} |
Oops, something went wrong.