Skip to content

Commit

Permalink
- Layout Updated
Browse files Browse the repository at this point in the history
- Improved Offline Mode
- Bug Fixes
  • Loading branch information
DRDO-IIT-Indore committed Aug 8, 2017
1 parent 43ff877 commit 8b48096
Show file tree
Hide file tree
Showing 23 changed files with 433 additions and 421 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ android {
applicationId "com.blackboxindia.PostIt"
minSdkVersion 21
targetSdkVersion 26
versionName '2.3'
versionName '2.32'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionCode 4
versionCode 6
}
buildTypes {
release {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="false"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.blackboxindia.PostIT.CustomViews;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.util.AttributeSet;


public class SquareCard extends CardView {

public SquareCard(Context context) {
super(context);
}

public SquareCard(Context context, AttributeSet attrs) {
super(context, attrs);
}

public SquareCard(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//noinspection SuspiciousNameCombination
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
}
95 changes: 84 additions & 11 deletions app/src/main/java/com/blackboxindia/PostIT/Fragments/Frag_Docs.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand All @@ -13,6 +15,7 @@
import android.view.ViewGroup;

import com.blackboxindia.PostIT.Network.CloudStorageMethods;
import com.blackboxindia.PostIT.Network.ConnectionDetector;
import com.blackboxindia.PostIT.Network.Interfaces.onCompleteListener;
import com.blackboxindia.PostIT.Network.NetworkMethods;
import com.blackboxindia.PostIT.R;
Expand All @@ -32,6 +35,7 @@ public class Frag_Docs extends Fragment {
SwipeRefreshLayout swipeRefreshLayout;
Context context;
Directory directory;
String college;
CloudStorageMethods cloudStorageMethods;

@Nullable
Expand All @@ -45,19 +49,61 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
swipeRefreshLayout = mainView.findViewById(R.id.docs_swipe_refresh_layout);
recyclerView = mainView.findViewById(R.id.docs_recycler);

if(((MainActivity)context).offlineMode){
if(((MainActivity)context).userInfo==null)
college = "IIT Indore";
else
college = ((MainActivity) context).userInfo.getCollegeName();

((MainActivity) context).offlineMode = !ConnectionDetector.isNetworkAvailable(context);

if (((MainActivity) context).offlineMode) {
swipeRefreshLayout.setRefreshing(true);
directory = Paper.book().read("Root", null);

if(directory != null){
//Log.i(TAG, "onCreateView: nice");
setUpRecycler();
}else
//Log.i(TAG, "onCreateView: ehh");
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
((MainActivity) context).offlineMode = !ConnectionDetector.isNetworkAvailable(context);
if(((MainActivity) context).offlineMode){
swipeRefreshLayout.setRefreshing(false);
((MainActivity) context).createSnackbar("Offline!", Snackbar.LENGTH_INDEFINITE, true, "Go Online", new View.OnClickListener() {
@Override
public void onClick(View view) {
((MainActivity) context).offlineMode = !ConnectionDetector.isNetworkAvailable(context);
if(((MainActivity) context).offlineMode){
((MainActivity) context).createSnackbar("No Network!");
}else {
((MainActivity) context).createSnackbar("Online!");
((MainActivity) context).goOnline(false);
}
}
});
}else {
getData();
}
}
});

swipeRefreshLayout.setRefreshing(false);
if (directory != null) {
setUpRecycler();
swipeRefreshLayout.setRefreshing(false);
} else {
swipeRefreshLayout.setRefreshing(false);
((MainActivity) context).createSnackbar("No Network!", Snackbar.LENGTH_INDEFINITE, true, "Go Online", new View.OnClickListener() {
@Override
public void onClick(View view) {
((MainActivity) context).offlineMode = !ConnectionDetector.isNetworkAvailable(context);
if(((MainActivity) context).offlineMode){
((MainActivity) context).createSnackbar("No Network!");
}else {
((MainActivity) context).createSnackbar("Online!");
((MainActivity) context).goOnline(false);
}
}
});
}

}else {
} else {
swipeRefreshLayout.setRefreshing(true);
getData();
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
Expand All @@ -81,12 +127,29 @@ private void setUpRecycler() {

public void getData() {

new NetworkMethods(context).getAllFiles(((MainActivity)context).userInfo.getCollegeName(), new onCompleteListener<Directory>() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if(directory==null){
if(swipeRefreshLayout.isRefreshing())
swipeRefreshLayout.setRefreshing(false);
directory = Paper.book().read("Root", null);
if(directory!=null) {
if (recyclerView.getAdapter() != null)
((DocumentAdapter) recyclerView.getAdapter()).changeRoot(directory);
else
setUpRecycler();
}
}
}
}, 1500);

new NetworkMethods(context).getAllFiles(college, new onCompleteListener<Directory>() {

@Override
public void onSuccess(Directory dir) {
((MainActivity) context).offlineMode = false;

Paper.init(context);
Paper.book().write("Root",dir);

directory = dir;
Expand All @@ -101,7 +164,17 @@ public void onSuccess(Directory dir) {

@Override
public void onFailure(Exception e) {
//Log.e(TAG, "onFailure: getDir", e);
Log.e(TAG, "onFailure: getDir", e);
if(swipeRefreshLayout.isRefreshing())
swipeRefreshLayout.setRefreshing(false);
directory = Paper.book().read("Root", null);
if(directory!=null) {
((MainActivity) context).createSnackbar("Viewing Documents offline");
if (recyclerView.getAdapter() != null)
((DocumentAdapter) recyclerView.getAdapter()).changeRoot(directory);
else
setUpRecycler();
}
}

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blackboxindia.PostIT.R;
import com.blackboxindia.PostIT.activities.MainActivity;
import com.blackboxindia.PostIT.dataModels.AdTypes;
import com.blackboxindia.PostIT.dataModels.UserInfo;

public class Frag_Main extends Fragment {

Expand Down Expand Up @@ -105,22 +103,6 @@ public void onClick(View v) {
mainActivity.launchOtherFragment(new Frag_Docs(),MainActivity.DOCS_TAG, true);
}
else {
// mainActivity.createSnackbar("Please Login to view Documents", Snackbar.LENGTH_INDEFINITE, true, "Login", new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// ((MainActivity)context).launchOtherFragment(new Frag_LoginPage(),MainActivity.LOGIN_PAGE_TAG, true);
// }
// });
UserInfo userInfo = new UserInfo();
userInfo.setCollegeName("IIT Indore");
userInfo.setName("Anonymous");
userInfo.setEmail("[email protected]");
userInfo.setHostel("");
userInfo.setuID("");
userInfo.setPhone("");
userInfo.setRoomNumber("");
userInfo.setHasProfileIMG(false);
((MainActivity)context).AnonLogin(userInfo);
mainActivity.launchOtherFragment(new Frag_Docs(),MainActivity.DOCS_TAG, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -242,8 +241,8 @@ private void prepareAndCreateAd() {

networkMethods = new NetworkMethods(context);

Bitmap major = adapter.getMajor();
if(major==null)
// Bitmap major = adapter.getMajor();
// if(major==null)
//Log.e(TAG, "prepareAndCreateAd: major null");

createAd(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,30 +447,33 @@ public String toString() {
public void downloadFile(String name, String college, final onCompleteListener<File> listener) {

final File file = new File(context.getExternalFilesDir(DIRECTORY_DOCUMENTS), name + ".pdf");
if (!file.exists()) {
FirebaseStorage.getInstance().getReference().child(DIRECTORY_DATA).child(college).child(name + ".pdf")
.getFile(file)
.addOnCompleteListener(new OnCompleteListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<FileDownloadTask.TaskSnapshot> task) {
if (task.isSuccessful()) {
final boolean downloaded = file.exists();

FirebaseStorage.getInstance().getReference().child(DIRECTORY_DATA).child(college).child(name + ".pdf")
.getFile(file)
.addOnCompleteListener(new OnCompleteListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<FileDownloadTask.TaskSnapshot> task) {
if (task.isSuccessful()) {
listener.onSuccess(file);
} else {
Log.e(TAG, "onComplete: failure", task.getException());
if(downloaded) {
listener.onSuccess(file);
} else {
//Log.e(TAG, "onComplete: failure", task.getException());
}
else {
listener.onFailure(task.getException());
}
}
})
.addOnProgressListener(new OnProgressListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onProgress(FileDownloadTask.TaskSnapshot taskSnapshot) {
float p = (taskSnapshot.getBytesTransferred() / taskSnapshot.getTotalByteCount()) * 100;
//Log.i(TAG, "onProgress downloadFile percentage: " + p);
}
});
}else {
listener.onSuccess(file);
}
}
})
.addOnProgressListener(new OnProgressListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onProgress(FileDownloadTask.TaskSnapshot taskSnapshot) {
float p = (taskSnapshot.getBytesTransferred() / taskSnapshot.getTotalByteCount()) * 100;
//Log.i(TAG, "onProgress downloadFile percentage: " + p);
}
});
}

public void getDownloadedFile(String name, String college, final onCompleteListener<File> listener) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.blackboxindia.PostIT.Network;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class ConnectionDetector {
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivityManager
= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();

return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
}
Loading

0 comments on commit 8b48096

Please sign in to comment.