Skip to content

Commit

Permalink
Updated favoriteActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
MansiBhayade committed Sep 28, 2023
1 parent 4d548de commit c80e851
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 14 deletions.
94 changes: 82 additions & 12 deletions app/src/main/java/dev/ukanth/iconmgr/FavoriteAcitvity.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
package dev.ukanth.iconmgr;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.os.Environment;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import com.afollestad.materialdialogs.MaterialDialog;
import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import dev.ukanth.iconmgr.dao.FavDao;


public class FavoriteAcitvity extends Activity {

private GridLayout gridLayout;

private LinearLayout.LayoutParams params;

public class FavoriteAcitvity extends AppCompatActivity {
FavDao favDao = App.getInstance().getFavDao();
private Context mContext;


@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.favorite);
mContext = FavoriteAcitvity.this;
setupActionBar();
LinearLayout iconPackContainer = findViewById(R.id.icon_pack_container);
List<String> iconName = favDao.geticonName();

Expand All @@ -54,7 +61,6 @@ protected void onCreate(Bundle savedInstanceState) {
// Create a TextView for the current icon name
TextView textView = new TextView(this);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); // Text size
textView.setTypeface(null, Typeface.BOLD);
textView.setText(icon);
// Add the TextView to the icon pack container
iconPackContainer.addView(textView);
Expand All @@ -73,18 +79,82 @@ protected void onCreate(Bundle savedInstanceState) {
for (byte[] iconImageData : iconImages) {
Bitmap bitmap = BitmapFactory.decodeByteArray(iconImageData, 0, iconImageData.length);

String icontitle = favDao.getIcontitleForIconImageData(iconImageData);

ImageView image = new ImageView(getApplicationContext());
image.setPadding(15, 15, 15, 15);
image.setScaleType(ImageView.ScaleType.FIT_CENTER);
image.setImageDrawable(new BitmapDrawable(getResources(), bitmap));

image.setOnClickListener(v -> {
View dialogView = LayoutInflater.from(mContext).inflate(R.layout.favorite_dialog, null);
ImageView saveImageView = dialogView.findViewById(R.id.saveImageView);
ImageView closeImageView = dialogView.findViewById(R.id.closeImageView);
ImageView removeImageView = dialogView.findViewById(R.id.removeImageView);
TextView titletextView = dialogView.findViewById(R.id.icon_title);

MaterialDialog dialog = new MaterialDialog.Builder(mContext)
.customView(dialogView, false)
.show();

titletextView.setText("Action for"+" "+ icontitle );

saveImageView.setOnClickListener(view -> {
File mediaDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
if (mediaDir == null) {
Log.e("MICO", "External storage not available");
return;
}
File myDir = new File(mediaDir, "micopacks/general/");
if (!myDir.exists() && !myDir.mkdirs()) {
Log.e("MICO", "Failed to create directory: " + myDir.getAbsolutePath());
return;
}
String fname = icontitle + ".png";
File file = new File(myDir, fname);
if (file.exists()) {
boolean deleted = file.delete();
if (deleted) {
Toast.makeText(getApplicationContext(), "Image deleted successfully", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Failed to delete image", Toast.LENGTH_SHORT).show();
}
return;
}
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 85, out);
out.flush();
out.close();
Toast.makeText(getApplicationContext(), "Icon saved successfully: " + file.getAbsolutePath(), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Log.e("MICO", e.getMessage(), e);
}
});

removeImageView.setOnClickListener(view -> {
favDao.deleteIcon(iconImageData);
Toast.makeText(mContext, "Removed from favorites: " , Toast.LENGTH_SHORT).show();

});

closeImageView.setOnClickListener(view -> {
dialog.dismiss();
});

});
// Add the ImageView to the GridLayout
iconGridLayout.addView(image);
}
// Add the GridLayout to the icon pack container
iconPackContainer.addView(iconGridLayout);

}

}
}
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
}
2 changes: 0 additions & 2 deletions app/src/main/java/dev/ukanth/iconmgr/IconPreviewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public class IconPreviewActivity extends AppCompatActivity {
private BroadcastReceiver uiProgressReceiver;
private IntentFilter uiFilter;

private boolean isFavorite ; // Initial state

IPObjDao ipObjDao = App.getInstance().getIPObjDao();

FavDao favDao = App.getInstance().getFavDao();
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/dev/ukanth/iconmgr/dao/FavDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ public interface FavDao {
@Update
void updateFavorite(Favorite favorite);

@Query("DELETE FROM favorite WHERE iconImageData = :imageData")
void deleteIcon(byte[] imageData);

@Query("DELETE FROM Favorite WHERE iconPkg = :packageName AND Icontitle = :iconTitle AND iconName = :iconName")
void deleteFavorite(String packageName, String iconTitle, String iconName);

@Query("SELECT Icontitle FROM Favorite WHERE iconImageData = :iconImageData LIMIT 1")
String getIcontitleForIconImageData(byte[] iconImageData);

@Query("SELECT iconImageData FROM Favorite WHERE iconName = :iconName ")
List<byte[]> getIconImageData(String iconName);

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/remove_from_favorites.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="122.88"
android:viewportHeight="109.57">
<path
android:fillColor="#FF000000"
android:pathData="M94.26,44.46A26.88,26.88 0,1 1,67.38 71.34,26.88 26.88,0 0,1 94.26,44.46ZM65.45,19.57l-4.52,4.74 -4.52,-4.43C49,12.58 43.4,7.08 31.89,6.93L30.46,7A25.75,25.75 0,0 0,13.74 13.6,22.58 22.58,0 0,0 6.63,30.17l0,1.37c0.69,19.27 19.13,36.08 34.42,50 3,2.69 5.78,5.27 8.49,7.88l11.27,10.85 5.91,-5.87c0.68,0.8 1.39,1.58 2.13,2.32l0,0c0.82,0.83 1.69,1.61 2.59,2.36l-10.59,10.5L45,94.22c-2.49,-2.39 -5.37,-5 -8.37,-7.75C20.37,71.68 0.81,53.85 0,31.77l0,-1.68A29.12,29.12 0,0 1,9.21 8.73a32.42,32.42 0,0 1,21 -8.42H32c14,0.18 20.45,6.34 28.8,14.55C67.66,7.54 73.39,1.55 85,0.21a33.88,33.88 0,0 1,19 3.45,35.14 35.14,0 0,1 12.51,10.48 31.53,31.53 0,0 1,6.1 15.18,31 31,0 0,1 -2.86,16.81l-0.17,-0.18a36.18,36.18 0,0 0,-5.14 -4.27,24.26 24.26,0 0,0 1.57,-11.6 25,25 0,0 0,-4.83 -12,28.62 28.62,0 0,0 -10.14,-8.5A27.27,27.27 0,0 0,85.79 6.82C76.47,7.89 71.5,13.17 65.45,19.57ZM106.15,68a4,4 0,0 1,1.51 0.3,3.94 3.94,0 0,1 1.29,0.86 4,4 0,0 1,0.85 1.28l0,0.06a4,4 0,0 1,0.28 1.38V72a3.82,3.82 0,0 1,-0.3 1.44,4 4,0 0,1 -0.86,1.29 3.88,3.88 0,0 1,-1.27 0.85l-0.07,0a4.23,4.23 0,0 1,-1.43 0.28H82.37a3.85,3.85 0,0 1,-1.51 -0.31l-0.06,0a3.92,3.92 0,0 1,-1.23 -0.83,3.87 3.87,0 0,1 -0.85,-1.28l0,-0.07A4.23,4.23 0,0 1,78.41 72v0a3.8,3.8 0,0 1,0.3 -1.51A3.95,3.95 0,0 1,82.34 68Z"
android:fillType="evenOdd"/>
</vector>
59 changes: 59 additions & 0 deletions app/src/main/res/layout/favorite_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>

<TextView
android:id="@+id/icon_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="25dp"
android:layout_margin="25dp"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="25dp"
>
<ImageView
android:id="@+id/saveImageView"
android:layout_width="50dp"
android:layout_height="70dp"
android:scaleType="fitCenter"
android:src="@drawable/download"
android:layout_marginStart="20dp"
/>

<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />

<ImageView
android:id="@+id/removeImageView"
android:layout_width="50dp"
android:layout_height="70dp"
android:scaleType="fitCenter"
android:src="@drawable/remove_from_favorites"
android:padding="3dp"
/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />

<ImageView
android:id="@+id/closeImageView"
android:layout_width="50dp"
android:layout_height="70dp"
android:src="@drawable/close"
android:layout_marginEnd="20dp"/>
</LinearLayout>
</LinearLayout>

0 comments on commit c80e851

Please sign in to comment.