Skip to content

Commit

Permalink
Reload the view on first run of app
Browse files Browse the repository at this point in the history
Signed-off-by: Umair Khan <omerjerk@gmail.com>

Conflicts:
	App/src/main/java/in/ac/dtu/subtlenews/MainFragment.java
  • Loading branch information
omerjerk authored and Arnav Gupta committed Dec 20, 2013
1 parent f9ed96d commit d902980
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
4 changes: 3 additions & 1 deletion App/src/main/java/in/ac/dtu/subtlenews/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public void onFinish() {

//Try to read shared prefs if they exist (most possibly they won't) else 3 hours is default
SharedPreferences defaultPrefs = PreferenceManager.getDefaultSharedPreferences(this);
new NewsAutoRefresh(this, 0, Integer.parseInt(defaultPrefs.getString("sync_frequency", "3")) * 60 * 60 * 1000);
int interval = Integer.parseInt(defaultPrefs.getString("sync_frequency", "3")) * 60 * 60 * 1000;
//start the autorefresh after a delay of value interval
new NewsAutoRefresh(this, interval, interval);

SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("MainRun", true);
Expand Down
4 changes: 2 additions & 2 deletions App/src/main/java/in/ac/dtu/subtlenews/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected ArrayList<JSONObject> doInBackground(Void... v) {
} catch (Exception e) {
e.printStackTrace();
if (Utils.isNetworkConnected(getActivity())) {
new UpdateNews(getActivity(), true).execute();
new UpdateNews(getActivity(), false, MainFragment.this).execute();
} else {
Toast.makeText(getActivity(), "Please turn on your internet connection!", Toast.LENGTH_SHORT).show();
}
Expand Down Expand Up @@ -312,4 +312,4 @@ public View getView(int position, View convertView, ViewGroup parent) {
}

}
}
}
28 changes: 23 additions & 5 deletions App/src/main/java/in/ac/dtu/subtlenews/UpdateNews.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,25 @@ public class UpdateNews extends AsyncTask <Void, Void, String> {

private Context context;
private Boolean ranAutomatically;
private MainFragment mainFragment = null;

public UpdateNews(Context context, Boolean ranAutomatically){
this(context, ranAutomatically, null);
}

public UpdateNews(Context context, Boolean ranAutomatically, MainFragment mainFragment){

public UpdateNews(Context context, Boolean autorun){
this.context = context;
ranAutomatically = autorun;
this.ranAutomatically = ranAutomatically;

if(mainFragment != null){
this.mainFragment = mainFragment;
}

Log.d("Update News", "Inside the constructor of UpdateNews class");
if (!autorun) {
((Activity)context).setProgressBarIndeterminateVisibility(true);
}
if (!ranAutomatically) {
((Activity)context).setProgressBarIndeterminateVisibility(true);
}
}

@Override
Expand All @@ -75,6 +85,14 @@ protected void onPostExecute(String r) {

if (!ranAutomatically) {
((Activity)context).setProgressBarIndeterminateVisibility(false);

// mainFragment will never be null when ranAutomatically is false
if(mainFragment == null){
Log.d("UpdateNews", "This fucking thing is null");
} else {
mainFragment.updateView();
}

}

Log.d("[GET RESPONSE]", r);
Expand Down

0 comments on commit d902980

Please sign in to comment.