Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Added renaming support
Browse files Browse the repository at this point in the history
  • Loading branch information
Nalin-Angrish committed Nov 5, 2020
1 parent 0728954 commit 276ac37
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
45 changes: 44 additions & 1 deletion app/src/main/java/com/nalinstudios/iscan/internal/PdfCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
import android.net.Uri;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -129,6 +132,8 @@ public boolean onMenuItemClick(MenuItem item) {
delete();
}else if (item.getTitle().toString().toLowerCase().contains("edit")){
edit();
}else if (item.getTitle().toString().toLowerCase().contains("rename")){
rename();
}
return true;
}
Expand Down Expand Up @@ -253,12 +258,50 @@ public void onClick(DialogInterface dialog, int which) {


/**
* A function to edit the file when the user wants to. (Currently not supported)
* A function to edit the file when the user wants to.
*/
private void edit(){
Intent i = new Intent(activity, PDFEditActivity.class);
i.setData(Uri.fromFile(getFile(file)));
activity.startActivity(i);
Toast.makeText(activity, "Signal Sent", Toast.LENGTH_LONG).show();
}


/**
* A function to rename the already scanned file.
*/
private void rename(){
View p = activity.getLayoutInflater().inflate(R.layout.rename_popup, null);
String name;
try {
name = file.getName().replace(".jpg","");
}catch (Exception e){
name = file.getName();
}
((TextView)p.findViewById(R.id.message)).setText("Rename ".concat(name).concat(" to:"));
final PopupWindow window = new PopupWindow(p, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
window.setAnimationStyle(android.R.style.Animation_Dialog);
window.showAtLocation(p, Gravity.CENTER, 0, 0);
window.getContentView().findViewById(R.id.end).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
EditText tBox = window.getContentView().findViewById(R.id.newPdfName);
window.dismiss();
if (Statics.isAvailable(tBox.getText().toString())){
String name = tBox.getText().toString();
File actual = getFile(file);
System.out.println(actual.renameTo(new File(actual.getParentFile(), name+".pdf")));
System.out.println(file.renameTo(new File(file.getParentFile(), name+".jpg")));
((MainActivity)activity).onResume();
}
}
});
window.getContentView().findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
window.dismiss();
}
});
}
}
74 changes: 74 additions & 0 deletions app/src/main/res/layout/rename_popup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:cardCornerRadius="20dp"
app:cardUseCompatPadding="true">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical"
android:layout_margin="10dp">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="30sp"
android:textStyle="bold|italic" />

<TextView
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<EditText
android:id="@+id/newPdfName"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/enter_name_for_pdf"
android:importantForAutofill="no"
android:inputType="textPersonName" />

<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="31dp"
android:layout_weight="1"
android:text="@string/pdf" />
</LinearLayout>

<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<Button
android:id="@+id/cancel"
style="?android:attr/buttonBarStyle"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/cancel" />

<Button
android:id="@+id/end"
style="?android:attr/buttonBarStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/submit" />
</LinearLayout>

</LinearLayout>
</androidx.cardview.widget.CardView>
4 changes: 4 additions & 0 deletions app/src/main/res/menu/card_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
android:id="@+id/two"
android:title="Delete" />

<item
android:id="@+id/three"
android:title="Rename" />

</menu>

0 comments on commit 276ac37

Please sign in to comment.