com.loopj.android.http.JsonHttpResponseHandler Java Examples

The following examples show how to use com.loopj.android.http.JsonHttpResponseHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AllNodesAdapter.java    From v2ex-daily-android with Apache License 2.0 6 votes vote down vote up
private void syncCollection(final int nodeId, final boolean added, String regTime){
    V2EX.syncCollection(mContext, nodeId, regTime, added, new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                if(response.getString("result").equals("ok")){
                    mProgressDialog.setMessage("OK");
                    mAllNodesDataHelper.setCollected(added, nodeId);
                }else if(response.getString("result").equals("fail")){
                    mProgressDialog.setMessage("Fail");
                    MessageUtils.toast(mContext, "Sync collections failed.");
                }
                mProgressDialog.dismiss();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}
 
Example #2
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
/**
 * @param action
 * @param contentId
 * @param collectionId The Id of the collection.
 * @param userToken    The token of the logged in user.
 * @param parameters
 * @param networkID    Livefyre provided network name
 * @param handler      Response handler
 * @throws MalformedURLException
 */
public static void featureMessage(String action, String contentId,
                                  String collectionId, String userToken,
                                  HashMap<String, Object> parameters, String networkID, JsonHttpResponseHandler handler)
        throws MalformedURLException {
    RequestParams bodyParams = new RequestParams();
    bodyParams.put("lftoken", userToken);

    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("collection")
            .appendPath(collectionId).appendPath(action)
            .appendPath(contentId).appendPath("")
            .appendQueryParameter("lftoken", userToken)
            .appendQueryParameter("collection_id", collectionId);

    Log.d("SDK", "" + uriBuilder);
    HttpClient.client.post(uriBuilder.toString(), bodyParams, handler);
}
 
Example #3
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
/**
 * @param action
 * @param contentId
 * @param collectionId The Id of the collection.
 * @param userToken    The token of the logged in user.
 * @param parameters
 * @param handler      Response handler
 * @throws MalformedURLException
 */

public static void featureMessage(String action, String contentId,
                                  String collectionId, String userToken,
                                  HashMap<String, Object> parameters, JsonHttpResponseHandler handler)
        throws MalformedURLException {
    RequestParams bodyParams = new RequestParams();
    bodyParams.put("lftoken", userToken);

    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("collection")
            .appendPath(collectionId).appendPath(action)
            .appendPath(contentId).appendPath("")
            .appendQueryParameter("lftoken", userToken)
            .appendQueryParameter("collection_id", collectionId);

    Log.d("SDK", "" + uriBuilder);
    HttpClient.client.post(uriBuilder.toString(), bodyParams, handler);
}
 
Example #4
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        The token of the logged in user.
 * @param action
 * @param parameters
 * @param networkID    Livefyre provided network name.
 * @param handler      Response handler
 */
public static void flagContent(String collectionId, String contentId,
                               String token, LFSFlag action, RequestParams parameters,
                               String networkID, JsonHttpResponseHandler handler) {

    String url = (new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("")) +
            contentId + (new Uri.Builder().appendPath("").appendPath("flag")
            .appendPath(flags[action.value()])
            .appendQueryParameter("lftoken", token)
            .appendQueryParameter("collection_id", collectionId));

    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
 
Example #5
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        The token of the logged in user.
 * @param action
 * @param parameters
 * @param handler      Response handler
 */

public static void flagContent(String collectionId, String contentId,
                               String token, LFSFlag action, RequestParams parameters,
                               JsonHttpResponseHandler handler) {

    String url = (new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("")) +
            contentId + (new Uri.Builder().appendPath("").appendPath("flag")
            .appendPath(flags[action.value()])
            .appendQueryParameter("lftoken", token)
            .appendQueryParameter("collection_id", collectionId));

    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
 
Example #6
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        The token of the logged in user.
 * @param action
 * @param parameters
 * @param handler      Response handler
 */

public static void postAction(String collectionId, String contentId,
                              String token, LFSActions action, RequestParams parameters,
                              JsonHttpResponseHandler handler) {
    // Build the URL
    String url = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("") + contentId +
            (new Uri.Builder().appendPath(actions[action.value()]).appendPath("")
                    .appendQueryParameter("lftoken", token)
                    .appendQueryParameter("collection_id", collectionId));


    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
 
Example #7
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        Livefyre Token
 * @param action
 * @param parameters
 * @param networkID    Livefyre provided network name
 * @param handler      Response handler
 */

public static void postAction(String collectionId, String contentId,
                              String token, LFSActions action, RequestParams parameters,
                              String networkID, JsonHttpResponseHandler handler) {
    // Build the URL
    String url = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("") + contentId +
            (new Uri.Builder().appendPath(actions[action.value()]).appendPath("")
                    .appendQueryParameter("lftoken", token)
                    .appendQueryParameter("collection_id", collectionId));


    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
 
Example #8
Source File: FlowApiRequests.java    From flow-android with MIT License 6 votes vote down vote up
public static void login(String facebookId, String facebookAccessToken,
                         final FlowApiRequestCallback callback) {
    RequestParams params = new RequestParams();
    params.put(Constants.FBID, facebookId);
    params.put(Constants.FACEBOOK_ACCESS_TOKEN, facebookAccessToken);

    FlowAsyncClient.post(Constants.API_LOGIN, params, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(JSONObject response) {
            Log.d(TAG, "Login success");
            callback.onSuccess(response);
        }

        @Override
        public void onFailure(String responseBody, Throwable error) {
            Log.d(TAG, "Login failed");
            callback.onFailure(responseBody);
        }
    });
}
 
Example #9
Source File: LoginActivity.java    From v2ex-daily-android with Apache License 2.0 6 votes vote down vote up
private void login(int onceCode){
    V2EX.login(LoginActivity.this, mUsername.getText().toString(), mPassword.getText().toString(), onceCode, new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            if(LoginActivity.this != null){
                try {
                    if(response.getString("result").equals("ok")){
                        mProgressDialog.setMessage("Get userinfo...");
                        getUserInfo();
                    }else if(response.getString("result").equals("fail")){
                        String errorContent = response.getJSONObject("content").getString("error_msg");
                        MessageUtils.toast(LoginActivity.this, errorContent);
                        mProgressDialog.dismiss();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}
 
Example #10
Source File: LoginActivity.java    From v2ex-daily-android with Apache License 2.0 6 votes vote down vote up
private void getOnceCode(){
    mProgressDialog = ProgressDialog.show(LoginActivity.this, null, "Get Once Code...", true, true);
    V2EX.getOnceCode(this, "https://www.v2ex.com/signin", new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            if(LoginActivity.this != null){
                try {
                    if(response.getString("result").equals("ok")){
                        int onceCode = response.getJSONObject("content").getInt("once");
                        mProgressDialog.setMessage("Login...");
                        login(onceCode);
                    }else{
                        MessageUtils.toast(LoginActivity.this, "get once code fail");
                    }
                } catch (JSONException e) {
                    MessageUtils.toast(LoginActivity.this, "json error");
                    e.printStackTrace();
                }
            }
        }
    });
}
 
Example #11
Source File: SearchAllNodeAdapter.java    From v2ex-daily-android with Apache License 2.0 6 votes vote down vote up
private void syncCollection(final int nodeId, final boolean added, String regTime){
    V2EX.syncCollection(mContext, nodeId, regTime, added, new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                if(response.getString("result").equals("ok")){
                    mProgressDialog.setMessage("OK");
                    mAllNodesDataHelper.setCollected(added, nodeId);
                }else if(response.getString("result").equals("fail")){
                    mProgressDialog.setMessage("Fail");
                    MessageUtils.toast(mContext, "Sync collections failed.");
                }
                mProgressDialog.dismiss();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}
 
Example #12
Source File: NodeFragment.java    From v2ex-daily-android with Apache License 2.0 6 votes vote down vote up
private void syncCollection(final int nodeId, final boolean added, String regTime){
    V2EX.syncCollection(getActivity(), nodeId, regTime, added, new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            if(getActivity() != null){
                try {
                    if(response.getString("result").equals("ok")){
                        mProgressDialog.setMessage("OK");
                        mAllNodesDataHelper.setCollected(added, nodeId);
                    }else if(response.getString("result").equals("fail")){
                        mProgressDialog.setMessage("Fail");
                        MessageUtils.toast(getActivity(), "Sync collections failed.");
                    }
                    mProgressDialog.dismiss();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}
 
Example #13
Source File: Helper.java    From KUAS-AP-Material with MIT License 6 votes vote down vote up
public static void getNews(final Context context) {
	mClient.get(NEWS_URL, new JsonHttpResponseHandler() {

		@Override
		public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
			super.onSuccess(statusCode, headers, response);
			// TODO wait for API update
			try {
				Memory.setString(context, Constant.PREF_NEWS_TITLE, response.getString(2));
				Memory.setString(context, Constant.PREF_NEWS_CONTENT, response.getString(3));
				Memory.setString(context, Constant.PREF_NEWS_URL, response.getString(4));
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
	});
}
 
Example #14
Source File: ListFragment.java    From ListItemFold with MIT License 6 votes vote down vote up
private void loadData() {
    AsyncHttpClient client = new AsyncHttpClient();

    client.get(getActivity(), "https://moment.douban.com/api/stream/date/2015-06-09", new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            if (response != null) {
                final JSONArray posts = response.optJSONArray("posts");
                int length = posts.length();
                List<SimpleData> resultDatas = new ArrayList<SimpleData>(length);
                for (int i = 0; i < length; i++) {
                    JSONObject obj = posts.optJSONObject(i);
                    SimpleData data = new SimpleData();
                    data.content = obj.optString("abstract");
                    data.title = obj.optString("title");
                    data.url = obj.optString("url");
                    JSONArray thumbs = obj.optJSONArray("thumbs");
                    if (thumbs.length() > 0) {
                        JSONObject thumb = thumbs.optJSONObject(0);
                        thumb = thumb.optJSONObject("large");
                        if (thumb != null) {
                            data.picUrl = thumb.optString("url");
                            resultDatas.add(data);
                        }
                    }
                }
                mAdapter.addAll(resultDatas);
            }
        }
    });
}
 
Example #15
Source File: Helper.java    From KUAS-AP-Material with MIT License 6 votes vote down vote up
public static void getNews(final Context context, final NewsCallback callback) {
	mClient.get(NEWS_ALL_URL, new JsonHttpResponseHandler() {

		@Override
		public void onSuccess(int statusCode, Header[] headers, JSONArray jsonArray) {
			super.onSuccess(statusCode, headers, jsonArray);
			try {
				List<NewsModel> modelList = new ArrayList<>();
				for (int i = 0; i < jsonArray.length(); i++) {
					NewsModel model = new NewsModel();
					model.title = jsonArray.getJSONObject(i).getString("news_title");
					model.image = jsonArray.getJSONObject(i).getString("news_image");
					model.weight = jsonArray.getJSONObject(i).getInt("news_weight");
					model.url = jsonArray.getJSONObject(i).getString("news_url");
					model.content = jsonArray.getJSONObject(i).getString("news_content");
					modelList.add(model);
				}
				if (callback != null) {
					callback.onSuccess(modelList);
				}
			} catch (JSONException e) {
				onHelperFail(context, callback, e);
			}
		}
	});
}
 
Example #16
Source File: Helper.java    From KUAS-AP-Material with MIT License 6 votes vote down vote up
public static void getNews(final Context context) {
	mClient.get(NEWS_URL, new JsonHttpResponseHandler() {

		@Override
		public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
			super.onSuccess(statusCode, headers, response);
			try {
				Memory.setString(context, Constant.PREF_NEWS_TITLE, response.getString(2));
				Memory.setString(context, Constant.PREF_NEWS_CONTENT, response.getString(3));
				Memory.setString(context, Constant.PREF_NEWS_URL, response.getString(4));
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
	});
}
 
Example #17
Source File: RecyclerFragment.java    From ListItemFold with MIT License 6 votes vote down vote up
private void loadData() {
    AsyncHttpClient client = new AsyncHttpClient();

    client.get(getActivity(), "https://moment.douban.com/api/stream/date/2015-06-09", new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            if (response != null) {
                final JSONArray posts = response.optJSONArray("posts");
                int length = posts.length();
                List<SimpleData> resultDatas = new ArrayList<SimpleData>(length);
                for (int i = 0; i < length; i++) {
                    JSONObject obj = posts.optJSONObject(i);
                    SimpleData data = new SimpleData();
                    data.content = obj.optString("abstract");
                    data.title = obj.optString("title");
                    data.url = obj.optString("url");
                    JSONArray thumbs = obj.optJSONArray("thumbs");
                    if (thumbs.length() > 0) {
                        JSONObject thumb = thumbs.optJSONObject(0);
                        thumb = thumb.optJSONObject("large");
                        if (thumb != null) {
                            data.picUrl = thumb.optString("url");
                            resultDatas.add(data);
                        }
                    }
                }
                mAdapter.addAll(resultDatas);
            }
        }
    });
}
 
Example #18
Source File: ApiConnector.java    From AnimeTaste with MIT License 5 votes vote down vote up
public void getCategoryRecommend(int categoryId,int count,JsonHttpResponseHandler handler){
    long timestamp = System.currentTimeMillis()/1000L;
    TreeMap<String,String> params = new TreeMap<String, String>();
    params.put("api_key",API_KEY);
    params.put("timestamp",String.valueOf(timestamp));
    params.put("limit",String.valueOf(count));
    params.put("feature",String.valueOf(1));
    params.put("category",String.valueOf(categoryId));
    String access_token = ApiUtils.getAccessToken(params,API_SECRET);
    String request = String.format(RECOMMEND_CATEGORY_REQUEST,API_KEY,timestamp,categoryId,count,access_token);
    get(request,handler);
}
 
Example #19
Source File: ApiConnector.java    From AnimeTaste with MIT License 5 votes vote down vote up
public void getALLRecommend(int count,JsonHttpResponseHandler handler){
    long timestamp = System.currentTimeMillis()/1000L;
    TreeMap<String,String> params = new TreeMap<String, String>();
    params.put("api_key",API_KEY);
    params.put("timestamp",String.valueOf(timestamp));
    params.put("limit",String.valueOf(count));
    params.put("feature",String.valueOf(1));
    String access_token = ApiUtils.getAccessToken(params,API_SECRET);
    String request = String.format(RECOMMEND_ALL_REQUEST,API_KEY,timestamp,count,access_token);
    get(request,handler);
}
 
Example #20
Source File: ApiConnector.java    From AnimeTaste with MIT License 5 votes vote down vote up
public void getCategory(int categoryId,int page,int count,JsonHttpResponseHandler handler){
    long timeStamp = System.currentTimeMillis() / 1000L;
    TreeMap<String,String> params = new TreeMap<String, String>();
    params.put("api_key",API_KEY);
    params.put("timestamp",String.valueOf(timeStamp));
    params.put("page",String.valueOf(page));
    params.put("category",String.valueOf(categoryId));
    params.put("limit",String.valueOf(count));
    String access_token = ApiUtils.getAccessToken(params,API_SECRET);
    String request = String.format(CATEGORY_REQUEST_URL,API_KEY,timeStamp,page,categoryId,count,access_token);
    get(request, handler);
}
 
Example #21
Source File: FlowApiRequests.java    From flow-android with MIT License 5 votes vote down vote up
private static void getDetails(String uri, final FlowApiRequestCallback callback) {
    FlowAsyncClient.get(uri, null, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(org.json.JSONObject response) {
            // Successfully got a response
            callback.onSuccess(response);
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseBody, Throwable e) {
            callback.onFailure(responseBody);
        }
    });
}
 
Example #22
Source File: FlowApiRequests.java    From flow-android with MIT License 5 votes vote down vote up
private static void getDetails(final int id, String uri, final FlowApiRequestCallback callback) {
    FlowAsyncClient.get(uri, null, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(org.json.JSONObject response) {
            FlowNetworkAsyncParser parser = new FlowNetworkAsyncParser(callback, id);
            parser.execute(response);
        }

        @Override
        public void onFailure(String responseBody, Throwable error) {
            callback.onFailure(responseBody);
        }
    });
}
 
Example #23
Source File: FlowApiRequests.java    From flow-android with MIT License 5 votes vote down vote up
public static void addCourseToShortlist(final String courseId, final FlowApiRequestCallback callback) {
    String url = String.format(Constants.API_USER_SHORTLIST_COURSE, courseId);
    FlowAsyncClient.put(url, null, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(JSONObject response) {
            Log.d(TAG, "Add course " + courseId +  " to shortlist success.");
            callback.onSuccess(response);
        }

        @Override
        public void onFailure(String responseBody, Throwable error) {
            Log.d(TAG, "Add course " + courseId +  " to shortlist failed.");
            callback.onFailure(responseBody);
        }

        @Override
        public void onFailure(Throwable e, JSONObject errorResponse) {
            Log.d(TAG, "Add course " + courseId +  " to shortlist failed.");

            String errorMessage = "";
            try {
                errorMessage = errorResponse.getString("error");
            } catch (JSONException e1) {
                // Ignore could not parse error message
            }

            callback.onFailure(errorMessage);
        }
    });
}
 
Example #24
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 5 votes vote down vote up
/**
 * @param authorId   Author of Post
 * @param token      Livefyre Token
 * @param parameters Parameters includes network,
 * @param handler    Response handler
 */

public static void flagAuthor(String authorId, String token,
                              RequestParams parameters, JsonHttpResponseHandler handler) {
    // Build the URL

    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("author");
    String url = uriBuilder + "/" + authorId + (new Uri.Builder().appendPath("ban").appendPath("").appendQueryParameter("lftoken", token));

    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
 
Example #25
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 5 votes vote down vote up
/**
 * @param authorId   Author of Post
 * @param token      Livefyre Token
 * @param parameters
 * @param networkID  Livefyre provided network name
 * @param handler    Response handler
 */
public static void flagAuthor(String authorId, String token,
                              RequestParams parameters, String networkID, JsonHttpResponseHandler handler) {
    // Build the URL

    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("author");
    String url = uriBuilder + "/" + authorId + (new Uri.Builder().appendPath("ban").appendPath("").appendQueryParameter("lftoken", token));

    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
 
Example #26
Source File: LoginActivity.java    From v2ex-daily-android with Apache License 2.0 5 votes vote down vote up
private void getUserInfo(){
    V2EX.getUserInfo(LoginActivity.this, new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            DebugUtils.log(response);
            try{
                String username = response.getJSONObject("content").getString("username");
                mProgressDialog.setMessage("Import Node Collections...");
                JSONArray collectionsJson = response.getJSONObject("content").getJSONArray("collections");
                String[] collections = new String[collectionsJson.length()];
                for(int i = 0; i < collections.length; i++){
                    collections[i] = collectionsJson.getString(i);
                }
                mAllNodesDataHelper.removeCollections();
                mAllNodesDataHelper.importCollections(collections);
                MessageUtils.toast(LoginActivity.this, "Hello, " + username);
                long currentTimeMillis = System.currentTimeMillis();
                PreferenceManager.getDefaultSharedPreferences(LoginActivity.this).edit()
                        .putString("username", username)
                        .putLong("sync_time", currentTimeMillis)
                        .commit();
                mProgressDialog.dismiss();
                Intent intent = new Intent();
                intent.putExtra("username", username);
                intent.putExtra("sync_time", currentTimeMillis);
                setResult(RESULT_OK, intent);
                finish();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}
 
Example #27
Source File: SearchAllNodeAdapter.java    From v2ex-daily-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(final int nodeId, final boolean added) {
    if(mIsLogined){
        if(added){
            mProgressDialog = ProgressDialog.show(mContext, null, "Add to collections...", true, false);
        }else{
            mProgressDialog = ProgressDialog.show(mContext, null, "Remove from collections...", true, false);
        }
        if(mRegTime == null){
            V2EX.getRegTime(mContext, new JsonHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                    try {
                        if (response.getString("result").equals("ok")) {
                            mRegTime = response.getString("reg_time");
                            mSharedPreferences.edit().putString("reg_time", mRegTime).commit();
                            syncCollection(nodeId, added, mRegTime);
                        } else if (response.getString("result").equals("fail")) {
                            MessageUtils.toast(mContext, "Get reg time fail");
                            mProgressDialog.dismiss();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
        }else{
            syncCollection(nodeId, added, mRegTime);
        }
    }else{
        mAllNodesDataHelper.setCollected(added, nodeId);
    }
}
 
Example #28
Source File: ApiConnector.java    From AnimeTaste with MIT License 5 votes vote down vote up
public void getDetail(int vid,JsonHttpResponseHandler handler){
    long timestamp = System.currentTimeMillis()/1000L;
    TreeMap<String,String> params = new TreeMap<String,String>();
    params.put("api_key",API_KEY);
    params.put("timestamp",String.valueOf(timestamp));
    params.put("vid",String.valueOf(vid));
    String access_token = ApiUtils.getAccessToken(params,API_SECRET);
    String request = String.format(ANIMATION_DETAIL_URL,API_KEY,timestamp,vid,access_token);
    get(request, handler);
}
 
Example #29
Source File: AllNodesAdapter.java    From v2ex-daily-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(final int nodeId, final boolean added) {
    if(mIsLogined){
        if(added){
            mProgressDialog = ProgressDialog.show(mContext, null, "Add to collections...", true, false);
        }else{
            mProgressDialog = ProgressDialog.show(mContext, null, "Remove from collections...", true, false);
        }
        if(mRegTime == null){
            V2EX.getRegTime(mContext, new JsonHttpResponseHandler(){
                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                    try {
                        if(response.getString("result").equals("ok")){
                            mRegTime = response.getString("reg_time");
                            mSharedPreferences.edit().putString("reg_time", mRegTime).commit();
                            syncCollection(nodeId, added, mRegTime);
                        }else if(response.getString("result").equals("fail")){
                            MessageUtils.toast(mContext, "Get reg time fail");
                            mProgressDialog.dismiss();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
        }else{
            syncCollection(nodeId, added, mRegTime);
        }
    }else{
        mAllNodesDataHelper.setCollected(added, nodeId);
    }
}
 
Example #30
Source File: ApiConnector.java    From AnimeTaste with MIT License 5 votes vote down vote up
public void getInitData(int animeCount,int featureCount,int advertiseCount,JsonHttpResponseHandler handler){
    long timeStamp = System.currentTimeMillis()/1000L;
    TreeMap<String,String> params = new TreeMap<String, String>();
    params.put("api_key",API_KEY);
    params.put("timestamp",String.valueOf(timeStamp));
    params.put("anime",String.valueOf(animeCount));
    params.put("feature",String.valueOf(featureCount));
    params.put("advert",String.valueOf(advertiseCount));
    String access_token = ApiUtils.getAccessToken(params,API_SECRET);
    String request = String.format(INIT_REQUEST_URL,API_KEY,timeStamp,animeCount,featureCount,advertiseCount,access_token);
    get(request, handler);
}