Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "added share feature for images on phone" #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -58,13 +63,16 @@ 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

@Override
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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -363,5 +386,4 @@ private void loadTodoLists() {
this.todoLists.addAll(todoLists);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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();
}

});
}
}

Expand All @@ -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);
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package com.oopcows.trackandtrigger.database;

import androidx.room.TypeConverter;
Expand Down Expand Up @@ -26,7 +25,7 @@ public static Profession fromString(String str) {
public static String fromTodos(ArrayList<Todo> 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();
}
Expand All @@ -35,30 +34,17 @@ public static String fromTodos(ArrayList<Todo> todos) {
public static ArrayList<Todo> fromDelimitedString(String delimitedString) {
ArrayList<Todo> todos = new ArrayList<Todo>();
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;
Expand All @@ -68,7 +54,7 @@ else if(ch == '\3') {
public static String getData(ArrayList<CategoryItem> 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();
}
Expand All @@ -80,7 +66,6 @@ public static ArrayList<CategoryItem> 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++;
Expand All @@ -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();
Expand Down
Loading