Skip to content

Commit

Permalink
Merge remote-tracking branch 'teamOSC/notes'
Browse files Browse the repository at this point in the history
  • Loading branch information
championswimmer committed Apr 26, 2015
2 parents 2cbe28c + b27b291 commit 28a3510
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 97 deletions.
5 changes: 0 additions & 5 deletions app/src/main/java/in/tosc/studddin/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package in.tosc.studddin;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
Expand Down Expand Up @@ -203,11 +202,7 @@ public void done(ParseException e) {

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 131077 && resultCode == Activity.RESULT_OK) {
paths = data.getStringArrayExtra("all_path");
}
super.onActivityResult(requestCode, resultCode, data);

}

}
26 changes: 14 additions & 12 deletions app/src/main/java/in/tosc/studddin/fragments/NotesFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
Expand All @@ -30,7 +29,7 @@ public class NotesFragment extends Fragment {

ViewPager notesPager;
FragmentStatePagerAdapter fragmentPagerAdapter;
int p,s;
int p, s;
NotesUploadFragment notesUploadFragment;
SlidingTabLayout tabs;

Expand All @@ -51,11 +50,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
View rootView = inflater.inflate(R.layout.fragment_notes, container, false);
p = getActivity().getResources().getColor(R.color.colorPrimary);
s = getActivity().getResources().getColor(R.color.colorPrimaryDark);
ApplicationWrapper.setCustomTheme((ActionBarActivity) getActivity(),p,s);
ApplicationWrapper.setCustomTheme((ActionBarActivity) getActivity(), p, s);

fragmentPagerAdapter = new FragmentStatePagerAdapter(getChildFragmentManager()) {

String[] fragmentTitles = new String[] {
String[] fragmentTitles = new String[]{
getResources().getString(R.string.notes_fragment_title_search),
getResources().getString(R.string.notes_fragment_title_upload)
};
Expand Down Expand Up @@ -110,14 +109,17 @@ public void goToOtherFragment(int position) {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (DEBUG) Log.d(TAG, "Request = " + requestCode + "result = " + resultCode);
String[] paths = data.getStringArrayExtra("all_path");
if (paths.length == 0)

notesUploadFragment.setImagePaths(paths, false);


notesUploadFragment.setImagePaths(paths, true);
String[] paths = null;
try {
paths = data.getStringArrayExtra("all_path");
if (paths.length == 0) {
notesUploadFragment.setImagePaths(paths, false);
} else {
notesUploadFragment.setImagePaths(paths, true);
}
} catch (Exception e) {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class NotesCustomDialog extends Dialog {
TextView dialogCollegeName, dialogBranchName, dialogTopicName, dialogSubjectName, dialogUploadedBy;
Button downloadNotes;
int position;
private DownloadManager downloadManager;
Context c;
private DownloadManager downloadManager;
private ArrayList<String> notesCollegeName, notesBranchName, notesTopicName, notesSubjectName, uploadedBy;

public NotesCustomDialog(Context activity, ArrayList<String> notesCollegeName,
Expand Down Expand Up @@ -65,7 +65,7 @@ protected void onCreate(Bundle savedInstanceState) {
dialogUploadedBy = (TextView) findViewById(R.id.notes_details_uploadedby);
downloadNotes = (Button) findViewById(R.id.notes_button_download);

downloadManager = (DownloadManager) this.c.getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager = (DownloadManager) this.c.getSystemService(Context.DOWNLOAD_SERVICE);

dialogUploadedBy.setText(uploadedBy.get(position));
dialogBranchName.setText(notesBranchName.get(position));
Expand All @@ -78,8 +78,9 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View v) {

if (DEBUG) Log.d(TAG, "" + position + notesSubjectName.get(position) + notesTopicName.get(position) + notesCollegeName.get(position) +
notesBranchName.get(position) );
if (DEBUG)
Log.d(TAG, "" + position + notesSubjectName.get(position) + notesTopicName.get(position) + notesCollegeName.get(position) +
notesBranchName.get(position));

ParseQuery<ParseObject> query = ParseQuery.getQuery("Notes");
query.whereEqualTo("subjectName", notesSubjectName.get(position));
Expand All @@ -94,14 +95,14 @@ public void onClick(View v) {
public void done(ParseObject notesParseObject, ParseException e) {

ArrayList<ParseFile> parseFileList = (ArrayList<ParseFile>) notesParseObject.get("notesImages");
if(!parseFileList.isEmpty()) {
for(ParseFile pFile : parseFileList) {
if (!parseFileList.isEmpty()) {
for (ParseFile pFile : parseFileList) {

;
String imageFileURL = pFile.getUrl();
Uri uri = Uri.parse(imageFileURL);
DownloadManager.Request dr = new DownloadManager.Request(uri);
dr.setTitle("Notes: " + notesTopicName.get(position)+ ".jpg");
dr.setTitle("Notes: " + notesTopicName.get(position) + ".jpg");
dr.setDescription("");

dr.setDestinationInExternalPublicDir("/LearnHut_Notes/",
Expand All @@ -112,7 +113,6 @@ public void done(ParseObject notesParseObject, ParseException e) {
}



}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.parse.GetDataCallback;
import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseImageView;

import java.util.ArrayList;

Expand Down Expand Up @@ -83,7 +80,7 @@ public int getItemCount() {


public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView topicNameTxtView;
public TextView topicNameTxtView;
public SimpleDraweeView notesImage;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void onClick(View v) {
searchEdTxt.setFocusableInTouchMode(true);
searchEdTxt.requestFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
});
swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshLayout);
Expand All @@ -154,11 +154,9 @@ public void onRefresh() {
getNotes();



searchEdTxt = (EditText) rootView.findViewById(R.id.notes_search);



addNotesButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -172,7 +170,6 @@ public void onClick(View v) {
}



public void goToUploadFragment() {
if (ApplicationWrapper.LOG_DEBUG) Log.d(TAG, "goToUploadFragment called");
NotesFragment notesFragment = (NotesFragment) getParentFragment();
Expand All @@ -199,7 +196,6 @@ public void done(List<ParseObject> parseObjects, ParseException e) {
notesFirstImage.add((ArrayList<ParseFile>) notes.get("notesImages"));



}
notesCustomGridViewAdapter = new NotesCustomGridViewAdapter(getActivity(), notesCollegeName,
notesBranchName, notesTopicName, notesSubjectName, notesFirstImage, uploadedBy);
Expand All @@ -209,6 +205,7 @@ public void done(List<ParseObject> parseObjects, ParseException e) {

});
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -55,14 +54,6 @@ public void setImagePaths(String[] paths, Boolean isSelected) {

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

String[] paths = data.getStringArrayExtra("all_path");
Log.d("Raghav", "Req = " + requestCode + "res = " + resultCode + "NotesUploadFragment");

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand Down Expand Up @@ -174,5 +165,4 @@ public void onClick(View v) {
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,40 @@ public class NotesUploadService extends Service {
public NotesUploadService() {
}

private static byte[] convertToByteArray(String imagePath) {
File file = new File(imagePath);

if (file.length() < 10485760) {
byte[] imageByte = new byte[(int) file.length()];
try {
Log.d("Raghav", "File Found");
FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream.read(imageByte);

} catch (FileNotFoundException e) {
Log.d("Raghav", "File Not Found.");

} catch (IOException e1) {
Log.d("Raghav", "Error Reading The File.");

}
return imageByte;

} else {
return null;
}
}

@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}



@Override
public int onStartCommand(Intent intent, int flags, int startId) {

final android.os.Handler mHandler=new android.os.Handler();
final android.os.Handler mHandler = new android.os.Handler();
parseFileList = new ArrayList<>();
final String[] imagePaths = intent.getStringArrayExtra("imagePaths");
final String userName = intent.getStringExtra("userName");
Expand All @@ -44,12 +66,12 @@ public int onStartCommand(Intent intent, int flags, int startId) {
final String topicNameString = intent.getStringExtra("topicName");


final Thread t = new Thread() {
final Thread t = new Thread() {

@Override
public void run() {
try {
for (int i = 0; i < imagePaths.length; i++) {
@Override
public void run() {
try {
for (int i = 0; i < imagePaths.length; i++) {
byte[] imageToBeUploaded = convertToByteArray(imagePaths[i]);
if (imageToBeUploaded == null) {
Toast.makeText(getApplicationContext(), "File size beyond limit", Toast.LENGTH_SHORT)
Expand All @@ -67,63 +89,39 @@ public void run() {
parseFileList.add(parseFile);
}

ParseObject uploadNotes = new ParseObject("Notes");
ParseObject uploadNotes = new ParseObject("Notes");

uploadNotes.addAll("notesImages", parseFileList);
uploadNotes.put("userName", ParseUser.getCurrentUser().getString("NAME"));
uploadNotes.put("subjectName", subjectNameString);
uploadNotes.put("topicName", topicNameString);
uploadNotes.put("branchName", branchNameString);
uploadNotes.put("collegeName", "DTU");
uploadNotes.addAll("notesImages", parseFileList);
uploadNotes.put("userName", ParseUser.getCurrentUser().getString("NAME"));
uploadNotes.put("subjectName", subjectNameString);
uploadNotes.put("topicName", topicNameString);
uploadNotes.put("branchName", branchNameString);
uploadNotes.put("collegeName", "DTU");

try {
uploadNotes.save();
mHandler.post(new Runnable(){
public void run(){
Toast.makeText(NotesUploadService.this, "Notes Uploaded Successfully", Toast.LENGTH_LONG).show();
}
});
try {
uploadNotes.save();
mHandler.post(new Runnable() {
public void run() {
Toast.makeText(NotesUploadService.this, "Notes Uploaded Successfully", Toast.LENGTH_LONG).show();
}
});


} catch (ParseException e) {
e.printStackTrace();
}
} catch (ParseException e) {
e.printStackTrace();
}


} finally {
} finally {

}
}
};
t.start();

}
};
t.start();


return START_STICKY;
//return super.onStartCommand(intent, flags, startId);

}
private static byte[] convertToByteArray(String imagePath) {
File file = new File(imagePath);

if (file.length() < 10485760) {
byte[] imageByte = new byte[(int) file.length()];
try {
Log.d("Raghav", "File Found");
FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream.read(imageByte);

} catch (FileNotFoundException e) {
Log.d("Raghav", "File Not Found.");

} catch (IOException e1) {
Log.d("Raghav", "Error Reading The File.");

}
return imageByte;

} else {
return null;
}
}
}

0 comments on commit 28a3510

Please sign in to comment.