Commit 85eb5c58 authored by DEEPAK VERMA's avatar DEEPAK VERMA

fixup! Merge branch 'send_reminder_feature' of /home/devil/Desktop/CS699...

fixup! Merge branch 'send_reminder_feature' of /home/devil/Desktop/CS699 Project/TalkingReminder-master-3bcd59a79d5a862510b2299d52c15f60c4d61295/remindme with conflicts.

Send Reminder Feature complete
parent 19166795
...@@ -47,7 +47,7 @@ dependencies { ...@@ -47,7 +47,7 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.bignerdranch.android:recyclerview-multiselect:0.2' implementation 'com.bignerdranch.android:recyclerview-multiselect:0.2'
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'com.google.code.gson:gson:2.8.6'
// Lombok Dependencies // Lombok Dependencies
......
...@@ -17,14 +17,17 @@ ...@@ -17,14 +17,17 @@
package com.blanyal.remindme; package com.blanyal.remindme;
import android.Manifest;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.DatePickerDialog; import android.app.DatePickerDialog;
import android.app.TimePickerDialog; import android.app.TimePickerDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.SyncStateContract;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.TextWatcher; import android.text.TextWatcher;
...@@ -38,17 +41,26 @@ import android.widget.TextView; ...@@ -38,17 +41,26 @@ import android.widget.TextView;
import android.widget.TimePicker; import android.widget.TimePicker;
import android.widget.Toast; import android.widget.Toast;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.content.FileProvider; import android.os.Environment;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.Calendar; import androidx.core.content.FileProvider;
import java.util.Calendar;
import com.google.gson.Gson;
import android.Manifest.permission;
public class ReminderAddActivity extends AppCompatActivity { public class ReminderAddActivity extends AppCompatActivity {
private Toolbar mToolbar; private Toolbar mToolbar;
...@@ -82,7 +94,7 @@ public class ReminderAddActivity extends AppCompatActivity { ...@@ -82,7 +94,7 @@ public class ReminderAddActivity extends AppCompatActivity {
private static final long milDay = 86400000L; private static final long milDay = 86400000L;
private static final long milWeek = 604800000L; private static final long milWeek = 604800000L;
private static final long milMonth = 2592000000L; private static final long milMonth = 2592000000L;
private static final int MY_PERMISSIONS_REQUEST_WRITE_CONTACTS = 1;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -356,6 +368,65 @@ public class ReminderAddActivity extends AppCompatActivity { ...@@ -356,6 +368,65 @@ public class ReminderAddActivity extends AppCompatActivity {
alert.show(); alert.show();
} }
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
//on clicking the send button
public void sendReminder(String filename){
/* mTitleText = (EditText) findViewById(R.id.reminder_title);
mDateText = (TextView) findViewById(R.id.set_date);
mTimeText = (TextView) findViewById(R.id.set_time);
mRepeatText = (TextView) findViewById(R.id.set_repeat);
mRepeatNoText = (TextView) findViewById(R.id.set_repeat_no);
mRepeatTypeText = (TextView) findViewById(R.id.set_repeat_type);
*/
Reminder talkingReminder=new Reminder();
talkingReminder.setTitle(mTitle);
talkingReminder.setDate(mDate);
talkingReminder.setTime(mTime);
talkingReminder.setRepeat(mRepeat);
talkingReminder.setRepeatNo(mRepeatNo);
talkingReminder.setRepeatType(mRepeatType);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
//String fileName=Environment.getExternalStorageDirectory()+"talkingReminder.json";
//First write the data to a temporary file
FileOutputStream outputStream;
if (ContextCompat.checkSelfPermission(ReminderAddActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
if (ActivityCompat.shouldShowRequestPermissionRationale(ReminderAddActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed; request the permission
ActivityCompat.requestPermissions(ReminderAddActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_WRITE_CONTACTS);
}
}
try {
String fileContents = gson.toJson(talkingReminder);
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(fileContents.getBytes());
outputStream.close();
// FileWriter fw = new FileWriter(filename);
// BufferedWriter bw = new BufferedWriter(fw);
// bw.write(content);
// bw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
// On clicking the save button // On clicking the save button
public void saveReminder(){ public void saveReminder(){
ReminderDatabase rb = new ReminderDatabase(this); ReminderDatabase rb = new ReminderDatabase(this);
...@@ -431,11 +502,13 @@ public class ReminderAddActivity extends AppCompatActivity { ...@@ -431,11 +502,13 @@ public class ReminderAddActivity extends AppCompatActivity {
if (mTitleText.getText().toString().trim().length() == 0) if (mTitleText.getText().toString().trim().length() == 0)
mTitleText.setError("Reminder Title cannot be blank!"); mTitleText.setError("Reminder Title cannot be blank!");
else { else {
saveReminder(); saveReminder();
} }
return true; return true;
// On clicking discard reminder button // On clicking discard reminder button
// Discard any changes // Discard any changes
case R.id.discard_reminder: case R.id.discard_reminder:
...@@ -451,31 +524,24 @@ public class ReminderAddActivity extends AppCompatActivity { ...@@ -451,31 +524,24 @@ public class ReminderAddActivity extends AppCompatActivity {
Context context = this; Context context = this;
//First write the data to a temporary file
String filename = Utility.FILE_NAME_PREFIX + "." + Utility.FILE_EXTENSION; //TODO Consecutive filenames should be unique String filename = Utility.FILE_NAME_PREFIX + "." + Utility.FILE_EXTENSION; //TODO Consecutive filenames should be unique
String fileContents = "First Send Reminder Test!!"; //TODO Write reminder data to file sendReminder(filename);
FileOutputStream outputStream;
// //Check the if the file was written correctly.. Should be printed on console
FileInputStream fi = null;
try { try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE); fi = context.openFileInput(filename);
outputStream.write(fileContents.getBytes()); int i;
outputStream.close(); StringBuilder sb = new StringBuilder();
while ((i=fi.read()) != -1)
sb.append((char)i);
System.out.println("******************************************************************");
System.out.println(sb.toString());
System.out.println("******************************************************************");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
// //Check the if the file was written correctly.. Should be printed on console
// FileInputStream fi = null;
// try {
// fi = context.openFileInput(filename);
// int i;
// StringBuilder sb = new StringBuilder();
// while ((i=fi.read()) != -1)
// sb.append((char)i);
// System.out.println(sb.toString());
// } catch (Exception e) {
// e.printStackTrace();
// }
//Pick the written file and send //Pick the written file and send
File filePath = context.getFilesDir(); File filePath = context.getFilesDir();
File fileToSend = new File(filePath, filename); File fileToSend = new File(filePath, filename);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment