Skip to content

Commit d600447

Browse files
authored
Merge pull request #80 from MobileApplicationsClub/fix-75
added worker for uploads
2 parents ab58e59 + d70c126 commit d600447

File tree

10 files changed

+520
-392
lines changed

10 files changed

+520
-392
lines changed

androidClient/app/build.gradle

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,24 @@ android {
3535

3636
dependencies {
3737
implementation fileTree(include: ['*.jar'], dir: 'libs')
38-
implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
39-
implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc01'
40-
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
38+
implementation 'androidx.appcompat:appcompat:1.0.0-rc02'
39+
implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc02'
40+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
4141
implementation 'com.google.android.material:material:1.0.0-rc01'
4242
implementation 'pub.devrel:easypermissions:1.2.0'
4343
implementation('com.google.api-client:google-api-client-android:1.23.0') {
4444
exclude group: 'org.apache.httpcomponents'
4545
}
46-
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.4'
46+
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
4747
implementation('com.google.apis:google-api-services-drive:v3-rev117-1.23.0') {
4848
exclude group: 'org.apache.httpcomponents'
4949
}
50-
implementation 'com.google.firebase:firebase-core:16.0.1'
50+
implementation 'com.google.firebase:firebase-core:16.0.3'
5151
implementation 'com.google.firebase:firebase-database:16.0.1'
52-
implementation 'com.google.firebase:firebase-auth:16.0.2'
53-
implementation 'com.google.firebase:firebase-messaging:17.1.0'
52+
implementation 'com.google.firebase:firebase-auth:16.0.3'
53+
implementation 'com.google.firebase:firebase-messaging:17.3.0'
5454
implementation 'com.google.firebase:firebase-config:16.0.0'
55-
implementation 'com.google.android.gms:play-services-auth:15.0.1'
55+
implementation 'com.google.android.gms:play-services-auth:16.0.0'
5656
implementation 'com.facebook.fresco:fresco:1.10.0'
5757
implementation 'com.squareup.okhttp:okhttp:2.7.5'
5858
def lifecycle_version = "2.0.0-rc01"
@@ -73,6 +73,10 @@ dependencies {
7373
implementation 'com.github.chrisbanes:PhotoView:2.1.4'
7474
implementation 'com.squareup.picasso:picasso:2.71828'
7575
implementation 'com.github.apl-devs:appintro:v4.2.3'
76+
def work_version = "1.0.0-alpha08"
77+
implementation "android.arch.work:work-runtime:$work_version" // use -ktx for Kotlin
78+
// optional - Firebase JobDispatcher support
79+
implementation "android.arch.work:work-firebase:$work_version"
7680
}
7781
apply plugin: 'com.google.gms.google-services'
7882
repositories {

androidClient/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
android:enabled="true">
5454

5555
</service>
56-
<service android:name=".coursematerial.UploadService" />
5756

5857
<activity
5958
android:name=".HomeActivity"
@@ -114,4 +113,4 @@
114113

115114
</application>
116115

117-
</manifest>
116+
</manifest>

androidClient/app/src/main/java/com/macbitsgoa/comrades/CHC.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const val TAG_PREFIX = "mac."
1515
const val BITS_EMAIL_SUFFIX = ".bits-pilani.ac.in"
1616
val firebaseRootRef: DatabaseReference = FirebaseDatabase.getInstance().reference
1717
.child(BuildConfig.BUILD_TYPE)
18-
18+
val courseMaterialRef: DatabaseReference = firebaseRootRef.child(FB_NODE_COURSE_MATERIAL)
1919
/**
2020
* [ValueEventListener] logging the error and delegating the user to implement
2121
* only [ValueEventListener.onDataChange]

androidClient/app/src/main/java/com/macbitsgoa/comrades/FirebaseKeys.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const val TOPIC_COURSE_UPDATES = BuildConfig.BUILD_TYPE + "CourseUpdates"
1313
const val COURSES = "courses"
1414
const val CONTRIBUTORS = "contributors"
1515
const val CONTRIBUTORS_NAME = "name"
16+
const val FB_NODE_COURSE_MATERIAL = "courseMaterial"
1617
/**
1718
* Get fcm channel name corresponding to the course
1819
*/

androidClient/app/src/main/java/com/macbitsgoa/comrades/coursematerial/CourseActivity.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ private void handleSort() {
245245
}).show();
246246
}
247247

248+
private void removeObservers() {
249+
materialVm.getMaterialListByFileType(courseId).removeObservers(this);
250+
materialVm.getMaterialListByName(courseId).removeObservers(this);
251+
materialVm.getMaterialListByTimestamp(courseId).removeObservers(this);
252+
materialVm.getMaterialListBySize(courseId).removeObservers(this);
253+
}
254+
248255
@Override
249256
public void onSaveInstanceState(final Bundle savedInstanceState) {
250257
super.onSaveInstanceState(savedInstanceState);
@@ -332,7 +339,7 @@ public void onClick(final View view) {
332339
private void showFragment() {
333340
final FragmentManager fm = getSupportFragmentManager();
334341
final FragmentTransaction ft = fm.beginTransaction();
335-
final DialogFragment uploadFileFragment = new UploadFileFragment();
342+
final DialogFragment uploadFileFragment = new UploadFileFragment(courseId);
336343
uploadFileFragment.show(ft, ADD_FILE_FRAGMENT);
337344
ft.addToBackStack(ADD_FILE_FRAGMENT);
338345
}
@@ -410,11 +417,5 @@ public void onResume() {
410417
.registerReceiver(broadcastReceiver, new IntentFilter(DownloadService.ACTION));
411418
}
412419

413-
private void removeObservers() {
414-
materialVm.getMaterialListByFileType(courseId).removeObservers(this);
415-
materialVm.getMaterialListByName(courseId).removeObservers(this);
416-
materialVm.getMaterialListByTimestamp(courseId).removeObservers(this);
417-
materialVm.getMaterialListBySize(courseId).removeObservers(this);
418-
}
419420
}
420421

androidClient/app/src/main/java/com/macbitsgoa/comrades/coursematerial/UploadFileFragment.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
import androidx.appcompat.app.AlertDialog;
2020
import androidx.fragment.app.DialogFragment;
21-
import androidx.fragment.app.Fragment;
2221

2322
import static android.app.Activity.RESULT_CANCELED;
2423
import static android.app.Activity.RESULT_OK;
2524
import static com.macbitsgoa.comrades.CHCKt.TAG_PREFIX;
2625
import static com.macbitsgoa.comrades.GetGoogleSignInActivity.KEY_TOKEN;
26+
import static com.macbitsgoa.comrades.coursematerial.Uploader.upload;
2727

2828
public class UploadFileFragment extends DialogFragment
2929
implements View.OnClickListener {
@@ -37,6 +37,11 @@ public class UploadFileFragment extends DialogFragment
3737
private FloatingActionButton fabAddImage;
3838
private TextView file;
3939
private String filePath;
40+
private String courseId;
41+
42+
public UploadFileFragment(final String courseId) {
43+
this.courseId = courseId;
44+
}
4045

4146
@Override
4247
public Dialog onCreateDialog(final Bundle savedInstanceState) {
@@ -57,8 +62,6 @@ public Dialog onCreateDialog(final Bundle savedInstanceState) {
5762
.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
5863
})
5964
.create();
60-
61-
6265
}
6366

6467
/**
@@ -72,7 +75,6 @@ private void initUi(final View view) {
7275
fabAddImage = view.findViewById(R.id.fab_image);
7376
fileName = view.findViewById(R.id.et_file_name);
7477
file = view.findViewById(R.id.tv_file_path);
75-
7678
}
7779

7880
private void setPositiveClick() {
@@ -86,10 +88,8 @@ private void setPositiveClick() {
8688
Toast.makeText(getContext(), R.string.warn_empty_file_name, Toast.LENGTH_LONG).show();
8789
return;
8890
}
89-
final Fragment dialogFragment = getActivity().getSupportFragmentManager()
90-
.findFragmentByTag(CourseActivity.ADD_FILE_FRAGMENT);
9191
final Intent signInIntent = new Intent(getActivity(), GetGoogleSignInActivity.class);
92-
dialogFragment.startActivityForResult(signInIntent, SIGN_IN_REQUEST_CODE);
92+
startActivityForResult(signInIntent, SIGN_IN_REQUEST_CODE);
9393
};
9494

9595

@@ -102,29 +102,27 @@ private void setPositiveClick() {
102102
*/
103103
@Override
104104
public void onClick(final View view) {
105-
final UploadFileFragment dialogFragment = (UploadFileFragment) getActivity().getSupportFragmentManager()
106-
.findFragmentByTag(CourseActivity.ADD_FILE_FRAGMENT);
107105
switch (view.getId()) {
108106
case R.id.fab_image:
109107
Intent imageIntent = new Intent();
110108
imageIntent.setType("image/*");
111109
imageIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
112110
imageIntent.setAction(Intent.ACTION_GET_CONTENT);
113-
dialogFragment.startActivityForResult(Intent.createChooser(imageIntent, "Select Picture"), REQUEST_CHOOSER);
111+
startActivityForResult(Intent.createChooser(imageIntent, "Select Picture"), REQUEST_CHOOSER);
114112
break;
115113

116114
case R.id.fab_doc:
117115
Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT);
118116
fileIntent.addCategory(Intent.CATEGORY_OPENABLE);
119117
fileIntent.setType("application/pdf");
120-
dialogFragment.startActivityForResult(Intent.createChooser(fileIntent, "Select Pdf"), REQUEST_CHOOSER);
118+
startActivityForResult(Intent.createChooser(fileIntent, "Select Pdf"), REQUEST_CHOOSER);
121119
break;
122120

123121
case R.id.fab_all_files:
124122
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
125123
intent.addCategory(Intent.CATEGORY_OPENABLE);
126124
intent.setType("*/*");
127-
dialogFragment.startActivityForResult(Intent.createChooser(intent, "Select File"), REQUEST_CHOOSER);
125+
startActivityForResult(Intent.createChooser(intent, "Select File"), REQUEST_CHOOSER);
128126
break;
129127
default:
130128
if (BuildConfig.DEBUG) {
@@ -146,11 +144,7 @@ public void onActivityResult(final int requestCode, final int resultCode, final
146144

147145
if (requestCode == SIGN_IN_REQUEST_CODE && resultCode == RESULT_OK) {
148146
final String accessToken = data.getStringExtra(KEY_TOKEN);
149-
Intent uploadIntent = UploadService.makeUploadIntent(getContext(), filePath,
150-
accessToken, fileName.getText().toString());
151-
Toast.makeText(getContext(), "Upload Started.Check NotificationBar for progress.",
152-
Toast.LENGTH_LONG).show();
153-
getActivity().startService(uploadIntent);
147+
upload(filePath, accessToken, fileName.getText().toString(), courseId);
154148
} else if (resultCode == RESULT_OK) {
155149
filePath = PathUtil.getPath(getContext(), data.getData());
156150
if (filePath != null) {
@@ -163,7 +157,5 @@ public void onActivityResult(final int requestCode, final int resultCode, final
163157
} else if (resultCode == RESULT_CANCELED) {
164158
Toast.makeText(getContext(), "No File Selected", Toast.LENGTH_LONG).show();
165159
}
166-
167160
}
168-
169161
}

0 commit comments

Comments
 (0)