From d6a2d3900369b3b1c5d9946688773be72e8e8af4 Mon Sep 17 00:00:00 2001 From: Vraj Gandhi <54766268+Victor-Titan@users.noreply.github.com> Date: Sun, 29 Nov 2020 13:07:05 +0530 Subject: [PATCH] Revert "added share feature for images on phone" --- .../dashboard/DashboardActivity.java | 42 +++-- .../categories/CategoryActivity.java | 7 +- .../dashboard/categories/ItemAdapter.java | 28 +-- .../trackandtrigger/database/Converters.java | 36 +--- .../trackandtrigger/helpers/Category.java | 166 +++++++++--------- .../trackandtrigger/helpers/CategoryItem.java | 5 +- .../res/drawable/ic_baseline_share_24.xml | 10 -- app/src/main/res/layout/category_item.xml | 12 +- 8 files changed, 129 insertions(+), 177 deletions(-) delete mode 100644 app/src/main/res/drawable/ic_baseline_share_24.xml diff --git a/app/src/main/java/com/oopcows/trackandtrigger/dashboard/DashboardActivity.java b/app/src/main/java/com/oopcows/trackandtrigger/dashboard/DashboardActivity.java index 2919fed..3eba847 100644 --- a/app/src/main/java/com/oopcows/trackandtrigger/dashboard/DashboardActivity.java +++ b/app/src/main/java/com/oopcows/trackandtrigger/dashboard/DashboardActivity.java @@ -1,13 +1,8 @@ package com.oopcows.trackandtrigger.dashboard; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.ActivityCompat; -import androidx.drawerlayout.widget.DrawerLayout; -import androidx.fragment.app.FragmentManager; -import androidx.recyclerview.widget.StaggeredGridLayoutManager; - import android.Manifest; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Bundle; import android.text.Editable; @@ -16,14 +11,24 @@ import android.view.Window; import android.widget.RelativeLayout; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.drawerlayout.widget.DrawerLayout; +import androidx.fragment.app.FragmentManager; +import androidx.recyclerview.widget.StaggeredGridLayoutManager; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; import com.mancj.materialsearchbar.MaterialSearchBar; +import com.oopcows.trackandtrigger.MainActivity; import com.oopcows.trackandtrigger.R; import com.oopcows.trackandtrigger.dashboard.categories.CategoryActivity; import com.oopcows.trackandtrigger.dashboard.todolists.TodoListActivity; import com.oopcows.trackandtrigger.database.DatabaseHelper; +import com.oopcows.trackandtrigger.databinding.ActivityDashboardBinding; import com.oopcows.trackandtrigger.helpers.Category; import com.oopcows.trackandtrigger.helpers.Profession; -import com.oopcows.trackandtrigger.databinding.ActivityDashboardBinding; import com.oopcows.trackandtrigger.helpers.Todo; import com.oopcows.trackandtrigger.helpers.TodoList; import com.oopcows.trackandtrigger.helpers.UserAccount; @@ -58,6 +63,7 @@ public class DashboardActivity extends AppCompatActivity implements ProfessionCh private DrawerLayout drawerLayout; private RelativeLayout leftRL; private boolean canUseInternet = false; + private DatabaseReference databaseReference; // @subs dashboardActivity should be in a sort of shadow while the dialogue is open // so that it is not visible until the profession has been chosen @@ -65,6 +71,8 @@ public class DashboardActivity extends AppCompatActivity implements ProfessionCh protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + databaseReference = FirebaseDatabase.getInstance().getReference(); + userAccount = getIntent().getExtras().getParcelable(USER_ACCOUNT_INTENT_KEY); isNewAccount = getIntent().getBooleanExtra(IS_NEW_ACCOUNT_INTENT_KEY, false); dh = DatabaseHelper.getInstance(this); @@ -154,15 +162,27 @@ private void createUI() { switchFragment(binding.triggerRoot); }); + binding.logoutButton.setOnClickListener((v) -> { + FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(); + SharedPreferences sharedPreferences = getSharedPreferences("sharedPrefs", MODE_PRIVATE); + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.clear(); + editor.apply(); + firebaseAuth.signOut(); + Intent mainActivity = new Intent(getBaseContext(), MainActivity.class); + startActivity(mainActivity); + }); + searchBar = binding.searchBar; searchBar.setSpeechMode(true); searchBar.addTextChangeListener(new TextWatcher() { @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - if(String.valueOf(charSequence).isEmpty()) { + if (String.valueOf(charSequence).isEmpty()) { binding.addCategory.setVisibility(View.VISIBLE); binding.addTodoList.setVisibility(View.VISIBLE); } @@ -286,6 +306,9 @@ private void downloadTodoLists() { private void uploadCategory(Category category) { // @vraj fill pls + databaseReference.child(FirebaseAuth.getInstance().getUid()).child(category.getCategoryName()); + + } private void uploadTodoList(TodoList todoList) { @@ -363,5 +386,4 @@ private void loadTodoLists() { this.todoLists.addAll(todoLists); } - } \ No newline at end of file diff --git a/app/src/main/java/com/oopcows/trackandtrigger/dashboard/categories/CategoryActivity.java b/app/src/main/java/com/oopcows/trackandtrigger/dashboard/categories/CategoryActivity.java index 614de82..381a1da 100644 --- a/app/src/main/java/com/oopcows/trackandtrigger/dashboard/categories/CategoryActivity.java +++ b/app/src/main/java/com/oopcows/trackandtrigger/dashboard/categories/CategoryActivity.java @@ -23,7 +23,6 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; -import android.os.StrictMode; import android.provider.MediaStore; import android.util.Log; import android.widget.Toast; @@ -55,15 +54,12 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(binding.getRoot()); specialCategoryName = ""; - StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); - StrictMode.setVmPolicy(builder.build()); - Intent intent = getIntent(); category = (Category) intent.getExtras().get(CATEGORY_INTENT_KEY); binding.categoryName.setText(category.getCategoryName()); itemAdapter = new ItemAdapter(this, binding.itemsLayout, new LinearLayoutManager(this), category.getItems()); binding.addItemButton.setOnClickListener((v) -> { - category.getItems().add(new CategoryItem("", "", 0, "")); + category.getItems().add(new CategoryItem("", "", 0)); itemAdapter.notifyItemChanged(category.getItems().size()-1); }); @@ -128,7 +124,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { String picturePath = cursor.getString(columnIndex); Bitmap bmp = BitmapFactory.decodeFile(picturePath); itemAdapter.getSelectedImageButton().setImageBitmap(bmp); - itemAdapter.setImgPathOfCurrentImgButton(picturePath); cursor.close(); } } diff --git a/app/src/main/java/com/oopcows/trackandtrigger/dashboard/categories/ItemAdapter.java b/app/src/main/java/com/oopcows/trackandtrigger/dashboard/categories/ItemAdapter.java index fb974ed..577ca54 100644 --- a/app/src/main/java/com/oopcows/trackandtrigger/dashboard/categories/ItemAdapter.java +++ b/app/src/main/java/com/oopcows/trackandtrigger/dashboard/categories/ItemAdapter.java @@ -4,7 +4,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; -import android.net.Uri; import android.text.Editable; import android.text.TextWatcher; import android.view.LayoutInflater; @@ -13,7 +12,6 @@ import android.widget.EditText; import android.widget.ImageButton; import android.widget.TextView; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; @@ -24,7 +22,6 @@ import com.oopcows.trackandtrigger.dashboard.categories.CategoryActivity; import com.oopcows.trackandtrigger.helpers.CategoryItem; -import java.io.File; import java.util.ArrayList; import static com.oopcows.trackandtrigger.helpers.CowConstants.CHOOSE_PICTURE_REQUEST_CODE; @@ -69,7 +66,7 @@ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - items.set(pos, new CategoryItem(String.valueOf(itemHolder.itemName.getText()), items.get(pos).getImgPath(), items.get(pos).getQuantity(), items.get(pos).getDownPath())); + items.set(pos, new CategoryItem(String.valueOf(itemHolder.itemName.getText()), items.get(pos).getImgPath(), items.get(pos).getQuantity())); } @Override @@ -87,25 +84,6 @@ public void afterTextChanged(Editable editable) {} itemHolder.itemImage.setClickable(false); setImage(itemHolder, items.get(pos).getImgPath()); } - itemHolder.shareButton.setOnClickListener((v) -> { - Uri imageUri = Uri.parse(items.get(itemHolder.getAdapterPosition()).getDownPath()); - Intent shareIntent = new Intent(); - shareIntent.setAction(Intent.ACTION_SEND); - //Target whatsapp: - shareIntent.setPackage("com.whatsapp"); - //Add text and then Image URI - shareIntent.putExtra(Intent.EXTRA_TEXT, "Item: " + itemHolder.itemName.getText()); - shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); - shareIntent.setType("image/jpeg"); - shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - - try { - categoryActivity.startActivity(shareIntent); - } catch (android.content.ActivityNotFoundException ex) { - ex.printStackTrace(); - } - - }); } } @@ -124,7 +102,6 @@ private static class ItemHolder extends RecyclerView.ViewHolder { private final ImageButton incQuantity, decQuantity; private final EditText itemName; private final TextView quantity; - private final ImageButton shareButton; public ItemHolder(@NonNull View itemView) { super(itemView); @@ -133,7 +110,6 @@ public ItemHolder(@NonNull View itemView) { decQuantity = itemView.findViewById(R.id.decreaseQuantity); itemName = itemView.findViewById(R.id.item_name); quantity = itemView.findViewById(R.id.quantity); - shareButton = itemView.findViewById(R.id.share_button); } } @@ -170,6 +146,6 @@ public ImageButton getSelectedImageButton() { public void setImgPathOfCurrentImgButton(String imgPath) { CategoryItem item = items.get(selectedHolder.getAdapterPosition()); - items.set(selectedHolder.getAdapterPosition(), new CategoryItem(item.getItemName(), imgPath, item.getQuantity(), imgPath)); + items.set(selectedHolder.getAdapterPosition(), new CategoryItem(item.getItemName(), imgPath, item.getQuantity())); } } diff --git a/app/src/main/java/com/oopcows/trackandtrigger/database/Converters.java b/app/src/main/java/com/oopcows/trackandtrigger/database/Converters.java index 27f5ad7..2aa7c14 100644 --- a/app/src/main/java/com/oopcows/trackandtrigger/database/Converters.java +++ b/app/src/main/java/com/oopcows/trackandtrigger/database/Converters.java @@ -1,4 +1,3 @@ - package com.oopcows.trackandtrigger.database; import androidx.room.TypeConverter; @@ -26,7 +25,7 @@ public static Profession fromString(String str) { public static String fromTodos(ArrayList todos) { StringBuilder result= new StringBuilder(); for(Todo todo : todos) { - result.append(todo.getTask()).append(todo).append('\1').append(todo.isDone() ? '\1' : '\2').append(todo.getTimeString()).append('\3'); + result.append(todo.getTask()).append(todo).append('\1').append(todo.isDone() ? '\1' : '\2'); } return result.toString(); } @@ -35,30 +34,17 @@ public static String fromTodos(ArrayList todos) { public static ArrayList fromDelimitedString(String delimitedString) { ArrayList todos = new ArrayList(); StringBuilder task = new StringBuilder(); - boolean isDone = false; - StringBuilder dateTime = new StringBuilder(); - boolean readingDatetime = false; for(int i = 0; i < delimitedString.length(); i++) { char ch = delimitedString.charAt(i); if(ch == '\1') { - readingDatetime = true; - } - else if(ch == '\2') { - isDone = true; - readingDatetime = true; - } - else if(ch == '\3') { - todos.add(new Todo(task.toString(), isDone, dateTime.toString())); + todos.add(new Todo(task.toString(), true, "0 0 0 0 0")); task = new StringBuilder(); - readingDatetime = false; } - else { - if(readingDatetime) { - dateTime.append(ch); - } - else { - task.append(ch); - } + else if (ch == '\2') { + todos.add(new Todo(task.toString(), false, "0 0 0 0 0")); + task = new StringBuilder(); + } else { + task.append(ch); } } return todos; @@ -68,7 +54,7 @@ else if(ch == '\3') { public static String getData(ArrayList items) { StringBuilder data = new StringBuilder(); for(CategoryItem item : items) { - data.append(item.getItemName()).append('\1').append(item.getImgPath()).append('\1').append(item.getQuantity()).append('\1').append(item.getDownPath()).append('\1'); + data.append(item.getItemName()).append('\1').append(item.getImgPath()).append('\1').append(item.getQuantity()).append('\1'); } return data.toString(); } @@ -80,7 +66,6 @@ public static ArrayList getFromData(String data) { StringBuilder itemName = new StringBuilder(); StringBuilder imgPath = new StringBuilder(); StringBuilder quantity = new StringBuilder(); - StringBuilder downPath = new StringBuilder(); for(int i = 0; i < data.length(); i++) { char ch = data.charAt(i); if(ch == '\1') delimiters++; @@ -94,10 +79,7 @@ else if(delimiters == 2) { quantity.append(ch); } else if(delimiters == 3) { - downPath.append(ch); - } - else if(delimiters==4) { - items.add(new CategoryItem(itemName.toString(), imgPath.toString(), Integer.parseInt(quantity.toString()), downPath.toString())); + items.add(new CategoryItem(itemName.toString(), imgPath.toString(), Integer.parseInt(quantity.toString()))); itemName = new StringBuilder(); imgPath = new StringBuilder(); quantity = new StringBuilder(); diff --git a/app/src/main/java/com/oopcows/trackandtrigger/helpers/Category.java b/app/src/main/java/com/oopcows/trackandtrigger/helpers/Category.java index e9ffad7..064858b 100644 --- a/app/src/main/java/com/oopcows/trackandtrigger/helpers/Category.java +++ b/app/src/main/java/com/oopcows/trackandtrigger/helpers/Category.java @@ -1,84 +1,82 @@ -package com.oopcows.trackandtrigger.helpers; - -import android.os.Parcel; -import android.os.Parcelable; - -import androidx.annotation.NonNull; -import androidx.room.ColumnInfo; -import androidx.room.Entity; -import androidx.room.Ignore; -import androidx.room.PrimaryKey; - -import java.util.ArrayList; - -import static com.oopcows.trackandtrigger.helpers.CowConstants.CATEGORIES_TABLE_NAME; -import static com.oopcows.trackandtrigger.helpers.CowConstants.CATEGORY_DATA_COLUMN; -import static com.oopcows.trackandtrigger.helpers.CowConstants.CATEGORY_NAME_COLUMN; - -@Entity(tableName = CATEGORIES_TABLE_NAME) -public class Category implements Parcelable { - - @ColumnInfo(name = CATEGORY_DATA_COLUMN) - private ArrayList items; - - @ColumnInfo(name = CATEGORY_NAME_COLUMN) - @PrimaryKey - @NonNull - private String categoryName; - - @Ignore - public Category(String categoryName) { - this.categoryName = categoryName; - items = new ArrayList(); - } - - public Category(String categoryName, ArrayList items) { - this.categoryName = categoryName; - this.items = items; - } - - protected Category(Parcel in) { - categoryName = in.readString(); - int size = in.readInt(); - items = new ArrayList(size); - for(int i = 0; i < size; i++) { - String itemName = in.readString(); - String imgPath = in.readString(); - int quantity = in.readInt(); - String downPath = in.readString(); - items.add(new CategoryItem(itemName, imgPath, quantity, downPath)); - } - } - - public static final Creator CREATOR = new Creator() { - @Override - public Category createFromParcel(Parcel in) { - return new Category(in); - } - - @Override - public Category[] newArray(int size) { - return new Category[size]; - } - }; - - public ArrayList getItems() { return items; } - public String getCategoryName() { return categoryName; } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(categoryName); - parcel.writeInt(items.size()); - for(CategoryItem item : items) { - parcel.writeString(item.getItemName()); - parcel.writeString(item.getImgPath()); - parcel.writeInt(item.getQuantity()); - parcel.writeString(item.getDownPath()); - } - } -} +package com.oopcows.trackandtrigger.helpers; + +import android.os.Parcel; +import android.os.Parcelable; + +import androidx.annotation.NonNull; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.Ignore; +import androidx.room.PrimaryKey; + +import java.util.ArrayList; + +import static com.oopcows.trackandtrigger.helpers.CowConstants.CATEGORIES_TABLE_NAME; +import static com.oopcows.trackandtrigger.helpers.CowConstants.CATEGORY_DATA_COLUMN; +import static com.oopcows.trackandtrigger.helpers.CowConstants.CATEGORY_NAME_COLUMN; + +@Entity(tableName = CATEGORIES_TABLE_NAME) +public class Category implements Parcelable { + + @ColumnInfo(name = CATEGORY_DATA_COLUMN) + private ArrayList items; + + @ColumnInfo(name = CATEGORY_NAME_COLUMN) + @PrimaryKey + @NonNull + private String categoryName; + + @Ignore + public Category(String categoryName) { + this.categoryName = categoryName; + items = new ArrayList(); + } + + public Category(String categoryName, ArrayList items) { + this.categoryName = categoryName; + this.items = items; + } + + protected Category(Parcel in) { + categoryName = in.readString(); + int size = in.readInt(); + items = new ArrayList(size); + for(int i = 0; i < size; i++) { + String itemName = in.readString(); + String imgPath = in.readString(); + int quantity = in.readInt(); + items.add(new CategoryItem(itemName, imgPath, quantity)); + } + } + + public static final Creator CREATOR = new Creator() { + @Override + public Category createFromParcel(Parcel in) { + return new Category(in); + } + + @Override + public Category[] newArray(int size) { + return new Category[size]; + } + }; + + public ArrayList getItems() { return items; } + public String getCategoryName() { return categoryName; } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(categoryName); + parcel.writeInt(items.size()); + for(CategoryItem item : items) { + parcel.writeString(item.getItemName()); + parcel.writeString(item.getImgPath()); + parcel.writeInt(item.getQuantity()); + } + } +} diff --git a/app/src/main/java/com/oopcows/trackandtrigger/helpers/CategoryItem.java b/app/src/main/java/com/oopcows/trackandtrigger/helpers/CategoryItem.java index 4e9dc04..812d3d8 100644 --- a/app/src/main/java/com/oopcows/trackandtrigger/helpers/CategoryItem.java +++ b/app/src/main/java/com/oopcows/trackandtrigger/helpers/CategoryItem.java @@ -5,19 +5,16 @@ public class CategoryItem { private String itemName; private String imgPath; private int quantity; - private String downPath; - public CategoryItem(String itemName, String imgPath, int quantity, String downPath) { + public CategoryItem(String itemName, String imgPath, int quantity) { this.itemName = itemName; this.imgPath = imgPath; this.quantity = quantity; - this.downPath = downPath; } public String getItemName() { return itemName; } public String getImgPath() { return imgPath; } public int getQuantity() { return quantity; } - public String getDownPath() { return downPath; } public void increaseQuantity() { quantity++; diff --git a/app/src/main/res/drawable/ic_baseline_share_24.xml b/app/src/main/res/drawable/ic_baseline_share_24.xml deleted file mode 100644 index 2f13bb3..0000000 --- a/app/src/main/res/drawable/ic_baseline_share_24.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/app/src/main/res/layout/category_item.xml b/app/src/main/res/layout/category_item.xml index 960f563..7cb643a 100644 --- a/app/src/main/res/layout/category_item.xml +++ b/app/src/main/res/layout/category_item.xml @@ -9,9 +9,8 @@ - - \ No newline at end of file