implement several loading progressbars
This commit is contained in:
parent
4faeb17461
commit
edbf27ffb8
@ -2,11 +2,13 @@ package org.fox.ttrss;
|
|||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.CharBuffer;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@ -15,6 +17,8 @@ import javax.net.ssl.SSLContext;
|
|||||||
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.TrustManager;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
|
import org.apache.http.util.CharArrayBuffer;
|
||||||
|
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -164,27 +168,31 @@ public class ApiRequest extends AsyncTask<HashMap<String,String>, Integer, JsonE
|
|||||||
OutputStream out = conn.getOutputStream();
|
OutputStream out = conn.getOutputStream();
|
||||||
out.write(postData);
|
out.write(postData);
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
m_responseCode = conn.getResponseCode();
|
m_responseCode = conn.getResponseCode();
|
||||||
m_responseMessage = conn.getResponseMessage();
|
m_responseMessage = conn.getResponseMessage();
|
||||||
|
|
||||||
switch (m_responseCode) {
|
switch (m_responseCode) {
|
||||||
case HttpURLConnection.HTTP_OK:
|
case HttpURLConnection.HTTP_OK:
|
||||||
BufferedReader buffer = new BufferedReader(
|
StringBuffer response = new StringBuffer();
|
||||||
new InputStreamReader(conn.getInputStream()), 8192);
|
InputStreamReader in = new InputStreamReader(conn.getInputStream(), "UTF-8");
|
||||||
|
char[] buf = new char[256];
|
||||||
String s = "";
|
int read = 0;
|
||||||
String response = "";
|
int total = 0;
|
||||||
|
|
||||||
while ((s = buffer.readLine()) != null) {
|
int contentLength = conn.getHeaderFieldInt("Api-Content-Length", -1);
|
||||||
response += s;
|
|
||||||
|
while ((read = in.read(buf)) >= 0) {
|
||||||
|
response.append(buf, 0, read);
|
||||||
|
total += read;
|
||||||
|
publishProgress(Integer.valueOf(total), Integer.valueOf(contentLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_transportDebugging) Log.d(TAG, "<<< " + response);
|
if (m_transportDebugging) Log.d(TAG, "<<< " + response);
|
||||||
|
|
||||||
JsonParser parser = new JsonParser();
|
JsonParser parser = new JsonParser();
|
||||||
|
|
||||||
JsonElement result = parser.parse(response);
|
JsonElement result = parser.parse(response.toString());
|
||||||
JsonObject resultObj = result.getAsJsonObject();
|
JsonObject resultObj = result.getAsJsonObject();
|
||||||
|
|
||||||
m_apiStatusCode = resultObj.get("status").getAsInt();
|
m_apiStatusCode = resultObj.get("status").getAsInt();
|
||||||
|
@ -32,9 +32,11 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.webkit.WebChromeClient;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
import android.webkit.WebViewClient;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
@ -98,6 +100,8 @@ public class ArticleFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
m_activity.setProgressBarVisibility(true);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
m_article = savedInstanceState.getParcelable("article");
|
m_article = savedInstanceState.getParcelable("article");
|
||||||
}
|
}
|
||||||
@ -125,6 +129,15 @@ public class ArticleFragment extends Fragment {
|
|||||||
WebView web = (WebView)view.findViewById(R.id.content);
|
WebView web = (WebView)view.findViewById(R.id.content);
|
||||||
|
|
||||||
if (web != null) {
|
if (web != null) {
|
||||||
|
web.setWebChromeClient(new WebChromeClient() {
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(WebView view, int progress) {
|
||||||
|
m_activity.setProgress(progress * 10000);
|
||||||
|
if (progress == 100) {
|
||||||
|
m_activity.setProgressBarVisibility(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
String content;
|
String content;
|
||||||
String cssOverride = "";
|
String cssOverride = "";
|
||||||
|
@ -126,13 +126,23 @@ public class ArticlePager extends Fragment {
|
|||||||
@SuppressWarnings({ "unchecked", "serial" })
|
@SuppressWarnings({ "unchecked", "serial" })
|
||||||
private void refresh(boolean append) {
|
private void refresh(boolean append) {
|
||||||
m_activity.setLoadingStatus(R.string.blank, true);
|
m_activity.setLoadingStatus(R.string.blank, true);
|
||||||
|
|
||||||
|
m_activity.setProgressBarVisibility(true);
|
||||||
|
|
||||||
if (!m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
|
if (!m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
|
||||||
append = false;
|
append = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity) {
|
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity) {
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(Integer... progress) {
|
||||||
|
m_activity.setProgress(progress[0] / progress[1] * 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onPostExecute(JsonElement result) {
|
protected void onPostExecute(JsonElement result) {
|
||||||
|
m_activity.setProgressBarVisibility(false);
|
||||||
|
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
@ -25,6 +25,7 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.Window;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
@ -127,7 +128,7 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
|
|||||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||||
ContextMenuInfo menuInfo) {
|
ContextMenuInfo menuInfo) {
|
||||||
|
|
||||||
getActivity().getMenuInflater().inflate(R.menu.category_menu, menu);
|
m_activity.getMenuInflater().inflate(R.menu.category_menu, menu);
|
||||||
|
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
||||||
FeedCategory cat = m_adapter.getItem(info.position);
|
FeedCategory cat = m_adapter.getItem(info.position);
|
||||||
@ -198,8 +199,7 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getActivity() != null)
|
m_activity.setProgressBarIndeterminateVisibility(showProgress);
|
||||||
getActivity().setProgressBarIndeterminateVisibility(showProgress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -210,13 +210,8 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
|
|||||||
final boolean unreadOnly = m_activity.getUnreadOnly();
|
final boolean unreadOnly = m_activity.getUnreadOnly();
|
||||||
|
|
||||||
if (sessionId != null) {
|
if (sessionId != null) {
|
||||||
|
setLoadingStatus(R.string.blank, true);
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
m_activity.setProgressBarVisibility(true);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
setLoadingStatus(R.string.blank, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
HashMap<String,String> map = new HashMap<String,String>() {
|
HashMap<String,String> map = new HashMap<String,String>() {
|
||||||
@ -231,7 +226,6 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
|
|||||||
};
|
};
|
||||||
|
|
||||||
req.execute(map);
|
req.execute(map);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +235,15 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
|
|||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(Integer... progress) {
|
||||||
|
m_activity.setProgress(Math.round((((float)progress[0] / (float)progress[1]) * 10000)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onPostExecute(JsonElement result) {
|
protected void onPostExecute(JsonElement result) {
|
||||||
|
m_activity.setProgressBarVisibility(false);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
try {
|
try {
|
||||||
JsonArray content = result.getAsJsonArray();
|
JsonArray content = result.getAsJsonArray();
|
||||||
|
@ -254,6 +254,8 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
|
|||||||
public void refresh(boolean background) {
|
public void refresh(boolean background) {
|
||||||
//FeedCategory cat = m_onlineServices.getActiveCategory();
|
//FeedCategory cat = m_onlineServices.getActiveCategory();
|
||||||
|
|
||||||
|
m_activity.setProgressBarVisibility(true);
|
||||||
|
|
||||||
final int catId = (m_activeCategory != null) ? m_activeCategory.id : -4;
|
final int catId = (m_activeCategory != null) ? m_activeCategory.id : -4;
|
||||||
|
|
||||||
final String sessionId = m_activity.getSessionId();
|
final String sessionId = m_activity.getSessionId();
|
||||||
@ -262,13 +264,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
|
|||||||
FeedsRequest req = new FeedsRequest(getActivity().getApplicationContext(), catId);
|
FeedsRequest req = new FeedsRequest(getActivity().getApplicationContext(), catId);
|
||||||
|
|
||||||
if (sessionId != null) {
|
if (sessionId != null) {
|
||||||
|
setLoadingStatus(R.string.blank, true);
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
setLoadingStatus(R.string.blank, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
HashMap<String,String> map = new HashMap<String,String>() {
|
HashMap<String,String> map = new HashMap<String,String>() {
|
||||||
{
|
{
|
||||||
@ -354,7 +350,15 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
|
|||||||
m_catId = catId;
|
m_catId = catId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(Integer... progress) {
|
||||||
|
m_activity.setProgress(Math.round((((float)progress[0] / (float)progress[1]) * 10000)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onPostExecute(JsonElement result) {
|
protected void onPostExecute(JsonElement result) {
|
||||||
|
m_activity.setProgressBarVisibility(false);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
try {
|
try {
|
||||||
JsonArray content = result.getAsJsonArray();
|
JsonArray content = result.getAsJsonArray();
|
||||||
|
@ -349,6 +349,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
if (m_activity != null) {
|
if (m_activity != null) {
|
||||||
m_refreshInProgress = true;
|
m_refreshInProgress = true;
|
||||||
|
|
||||||
|
m_activity.setProgressBarVisibility(true);
|
||||||
|
|
||||||
if (!m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
|
if (!m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
|
||||||
append = false;
|
append = false;
|
||||||
}
|
}
|
||||||
@ -359,7 +361,15 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
final boolean isCat = m_feed.is_cat;
|
final boolean isCat = m_feed.is_cat;
|
||||||
|
|
||||||
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity) {
|
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity) {
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(Integer... progress) {
|
||||||
|
m_activity.setProgress(Math.round((((float)progress[0] / (float)progress[1]) * 10000)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onPostExecute(JsonElement result) {
|
protected void onPostExecute(JsonElement result) {
|
||||||
|
m_activity.setProgressBarVisibility(false);
|
||||||
|
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
@ -132,8 +132,10 @@ public class OnlineActivity extends CommonActivity {
|
|||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
||||||
|
requestWindowFeature(Window.FEATURE_PROGRESS);
|
||||||
|
|
||||||
|
setProgressBarVisibility(false);
|
||||||
setProgressBarIndeterminateVisibility(false);
|
setProgressBarIndeterminateVisibility(false);
|
||||||
|
|
||||||
// SharedPreferences localPrefs = getSharedPreferences("localprefs", Context.MODE_PRIVATE);
|
// SharedPreferences localPrefs = getSharedPreferences("localprefs", Context.MODE_PRIVATE);
|
||||||
|
Loading…
Reference in New Issue
Block a user