From ab6ef873b243aed2837ab2bf1bdb200a19de279c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E5=A4=96=E6=A1=83=E6=BA=90?= Date: Sat, 7 Nov 2015 13:07:42 +0800 Subject: [PATCH] now its in better shape update more workable demo and SDK fragment --- .../hesk.xml => .idea/dictionaries/zJJ.xml | 2 +- disqus/.idea/vcs.xml => .idea/encodings.xml | 4 +- .idea/gradle.xml | 3 +- .idea/libraries/appcompat_v7_23_0_0.xml | 7 +- .idea/libraries/crashwoodpecker_0_9_7.xml | 10 + .idea/libraries/library_1_2_0.xml | 4 +- ...terialloadingprogressbar_0_5_3_RELEASE.xml | 7 +- .idea/libraries/recyclerview_v7_22_2_1.xml | 10 + .../libraries/support_annotations_23_0_0.xml | 4 +- .idea/libraries/support_v13_23_0_0.xml | 4 +- .idea/libraries/support_v4_23_0_0.xml | 7 +- .idea/misc.xml | 15 - .idea/workspace.xml | 1376 ++++---- app/app.iml | 21 +- app/build.gradle | 5 +- app/src/main/AndroidManifest.xml | 3 +- app/src/main/java/com/hkm/dis/Ap.java | 17 + app/src/main/java/com/hkm/dis/DqUtil.java | 20 + .../java/com/hkm/dis/applicationbase.java | 73 - app/src/main/java/com/hkm/dis/login.java | 92 - .../main/java/com/hkm/dis/mainTesting.java | 118 +- disqus/.idea/.name | 1 - disqus/.idea/compiler.xml | 22 - disqus/.idea/copyright/profiles_settings.xml | 3 - disqus/.idea/gradle.xml | 19 - .../.idea/libraries/appcompat_v7_22_1_1.xml | 15 - disqus/.idea/libraries/disqus_0_1_0.xml | 10 - disqus/.idea/libraries/gson_2_3.xml | 11 - disqus/.idea/libraries/okhttp_2_3_0.xml | 11 - .../libraries/okhttp_urlconnection_2_2_0.xml | 11 - disqus/.idea/libraries/okio_1_3_0.xml | 11 - disqus/.idea/libraries/picasso_2_5_0.xml | 11 - .../.idea/libraries/realm_android_0_80_0.xml | 11 - disqus/.idea/libraries/retrofit_1_7_1.xml | 11 - .../libraries/support_annotations_22_1_1.xml | 11 - disqus/.idea/libraries/support_v4_22_1_1.xml | 13 - disqus/.idea/misc.xml | 37 - disqus/.idea/modules.xml | 10 - disqus/.idea/workspace.xml | 2888 ----------------- disqus/disqus.iml | 20 +- disqus/src/main/AndroidManifest.xml | 13 +- .../hkm/disqus/{api => }/DisqusClient.java | 41 +- .../java/com/hkm/disqus/api/ApiClient.java | 13 +- ...hMgr.java => AuthTokenServiceManager.java} | 9 +- .../api/RefreshTokenBroadcastReceiver.java | 2 +- .../application/AuthorizationFragment.java | 154 +- .../disqus/application/AuthorizeActivity.java | 62 +- .../disqus/application/AuthorizeFragment.java | 212 -- .../application/PostCommentFragment.java | 89 + .../disqus/application/WebviewIntercept.java | 79 - .../application/authorizedcallback.java | 34 - ...xml => disqusloginactivityframelayout.xml} | 10 +- disqus/src/main/res/raw/embed | 12 - disqus/src/main/res/raw/embeddisqus | 15 - disqus/src/main/res/values/ids.xml | 2 + 55 files changed, 1112 insertions(+), 4563 deletions(-) rename disqus/.idea/dictionaries/hesk.xml => .idea/dictionaries/zJJ.xml (65%) rename disqus/.idea/vcs.xml => .idea/encodings.xml (52%) create mode 100644 .idea/libraries/crashwoodpecker_0_9_7.xml create mode 100644 .idea/libraries/recyclerview_v7_22_2_1.xml create mode 100644 app/src/main/java/com/hkm/dis/Ap.java create mode 100644 app/src/main/java/com/hkm/dis/DqUtil.java delete mode 100644 app/src/main/java/com/hkm/dis/applicationbase.java delete mode 100644 app/src/main/java/com/hkm/dis/login.java delete mode 100644 disqus/.idea/.name delete mode 100644 disqus/.idea/compiler.xml delete mode 100644 disqus/.idea/copyright/profiles_settings.xml delete mode 100644 disqus/.idea/gradle.xml delete mode 100644 disqus/.idea/libraries/appcompat_v7_22_1_1.xml delete mode 100644 disqus/.idea/libraries/disqus_0_1_0.xml delete mode 100644 disqus/.idea/libraries/gson_2_3.xml delete mode 100644 disqus/.idea/libraries/okhttp_2_3_0.xml delete mode 100644 disqus/.idea/libraries/okhttp_urlconnection_2_2_0.xml delete mode 100644 disqus/.idea/libraries/okio_1_3_0.xml delete mode 100644 disqus/.idea/libraries/picasso_2_5_0.xml delete mode 100644 disqus/.idea/libraries/realm_android_0_80_0.xml delete mode 100644 disqus/.idea/libraries/retrofit_1_7_1.xml delete mode 100644 disqus/.idea/libraries/support_annotations_22_1_1.xml delete mode 100644 disqus/.idea/libraries/support_v4_22_1_1.xml delete mode 100644 disqus/.idea/misc.xml delete mode 100644 disqus/.idea/modules.xml delete mode 100644 disqus/.idea/workspace.xml rename disqus/src/main/java/com/hkm/disqus/{api => }/DisqusClient.java (67%) rename disqus/src/main/java/com/hkm/disqus/api/{AuthMgr.java => AuthTokenServiceManager.java} (96%) delete mode 100644 disqus/src/main/java/com/hkm/disqus/application/AuthorizeFragment.java create mode 100644 disqus/src/main/java/com/hkm/disqus/application/PostCommentFragment.java delete mode 100644 disqus/src/main/java/com/hkm/disqus/application/WebviewIntercept.java delete mode 100644 disqus/src/main/java/com/hkm/disqus/application/authorizedcallback.java rename disqus/src/main/res/layout/{login.xml => disqusloginactivityframelayout.xml} (60%) delete mode 100644 disqus/src/main/res/raw/embed delete mode 100644 disqus/src/main/res/raw/embeddisqus diff --git a/disqus/.idea/dictionaries/hesk.xml b/.idea/dictionaries/zJJ.xml similarity index 65% rename from disqus/.idea/dictionaries/hesk.xml rename to .idea/dictionaries/zJJ.xml index 656325b..f1a4911 100644 --- a/disqus/.idea/dictionaries/hesk.xml +++ b/.idea/dictionaries/zJJ.xml @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/disqus/.idea/vcs.xml b/.idea/encodings.xml similarity index 52% rename from disqus/.idea/vcs.xml rename to .idea/encodings.xml index 6564d52..97626ba 100644 --- a/disqus/.idea/vcs.xml +++ b/.idea/encodings.xml @@ -1,6 +1,6 @@ - - + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 1e2c67b..13f66b2 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -3,8 +3,9 @@ \ No newline at end of file diff --git a/.idea/libraries/materialloadingprogressbar_0_5_3_RELEASE.xml b/.idea/libraries/materialloadingprogressbar_0_5_3_RELEASE.xml index 655eb3d..8a9e1a8 100644 --- a/.idea/libraries/materialloadingprogressbar_0_5_3_RELEASE.xml +++ b/.idea/libraries/materialloadingprogressbar_0_5_3_RELEASE.xml @@ -1,12 +1,13 @@ + + + - - - + \ No newline at end of file diff --git a/.idea/libraries/recyclerview_v7_22_2_1.xml b/.idea/libraries/recyclerview_v7_22_2_1.xml new file mode 100644 index 0000000..97c6570 --- /dev/null +++ b/.idea/libraries/recyclerview_v7_22_2_1.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_annotations_23_0_0.xml b/.idea/libraries/support_annotations_23_0_0.xml index 8a45179..62c44a1 100644 --- a/.idea/libraries/support_annotations_23_0_0.xml +++ b/.idea/libraries/support_annotations_23_0_0.xml @@ -1,11 +1,11 @@ - + - + \ No newline at end of file diff --git a/.idea/libraries/support_v13_23_0_0.xml b/.idea/libraries/support_v13_23_0_0.xml index 09765f5..dea86f0 100644 --- a/.idea/libraries/support_v13_23_0_0.xml +++ b/.idea/libraries/support_v13_23_0_0.xml @@ -1,13 +1,13 @@ - + - + \ No newline at end of file diff --git a/.idea/libraries/support_v4_23_0_0.xml b/.idea/libraries/support_v4_23_0_0.xml index 0a8405d..72853f5 100644 --- a/.idea/libraries/support_v4_23_0_0.xml +++ b/.idea/libraries/support_v4_23_0_0.xml @@ -1,13 +1,16 @@ + + + - + - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c77a17d..95f0f03 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -43,19 +43,4 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e51f666..be6d855 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -33,30 +33,11 @@ - - - - - - - - - - - - - - - - - - - - - + @@ -71,40 +52,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -174,7 +121,30 @@ - + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + Android Lint + + + HTML + + + J2ME issuesJava + + + Java + + + Resource management issuesJava + + + Security issuesJava + + + Serialization issuesJava + + + Threading issuesJava + + + + + Android + + + + + @@ -2868,114 +3048,121 @@ - - + - - - - - - - - - + + - - + + + + + + + + - - - + + + + + + - - - + + - - - @@ -2989,7 +3176,7 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3283,24 +3255,23 @@ - + - - + + + + - - - + - @@ -3309,15 +3280,23 @@ - + + + + + + + + + + - + - - + + + + + - - - - - - - - - - - - - - - - - + + + - - + + + + + + + + + + + - - + + + + @@ -3623,16 +3598,16 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3688,13 +3635,6 @@ - - - - - - - @@ -3702,20 +3642,6 @@ - - - - - - - - - - - - - - @@ -3723,14 +3649,6 @@ - - - - - - - - @@ -3752,13 +3670,6 @@ - - - - - - - @@ -3773,13 +3684,6 @@ - - - - - - - @@ -3794,254 +3698,390 @@ - + - - + + - + - - + + - + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - + + - + - - + + - + + + + + + + + + + + + + + + + + - - + + - + - + - - + + - + - - + + - + - + - + - - + + + + + - + - - + + - + - - + + - + - - + + + + + + + + + + + + - + - - + + - - - + + + + + + + + - - + + - + - - + + - + + - + - - + + - - - - + - - + + - + - - + + - - - + + + + + + + + + - - + + + + + + + + + + - - + + + + - + - - + + - + - - - + + + + + - + - - + + - + - - + + + + + + + + + + + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + - - - + + + + + + - + - - - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/app.iml b/app/app.iml index 90b73d7..52629f6 100644 --- a/app/app.iml +++ b/app/app.iml @@ -93,8 +93,10 @@ + + @@ -108,22 +110,25 @@ + - - - - - - + + - + + + + + + + + - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index b0bdfba..b9b8c74 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,10 +44,13 @@ dependencies { compile 'com.android.support:support-annotations:23.0.0' compile 'com.android.support:appcompat-v7:23.0.0' compile 'com.android.support:support-v13:23.0.0' - compile project(':disqus') //compile 'DisqusSDK-Android:disqus:0.1.2@aar' compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0' compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.picasso:picasso:2.5.0' compile 'io.realm:realm-android:0.84.1' + + debugCompile 'me.drakeet.library:crashwoodpecker:0.9.7' + releaseCompile 'me.drakeet.library:crashwoodpecker-do-nothing:0.9.7' + compile project(':disqus') } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 63d76bc..6501555 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,7 +17,6 @@ diff --git a/app/src/main/java/com/hkm/dis/Ap.java b/app/src/main/java/com/hkm/dis/Ap.java new file mode 100644 index 0000000..afc7923 --- /dev/null +++ b/app/src/main/java/com/hkm/dis/Ap.java @@ -0,0 +1,17 @@ +package com.hkm.dis; + +import android.app.Application; + +import me.drakeet.library.CrashWoodpecker; + +/** + * Created by zJJ on 11/7/2015. + * + */ +public class Ap extends Application { + @Override + public void onCreate() { + super.onCreate(); + CrashWoodpecker.fly().to(this); + } +} diff --git a/app/src/main/java/com/hkm/dis/DqUtil.java b/app/src/main/java/com/hkm/dis/DqUtil.java new file mode 100644 index 0000000..0bd4edd --- /dev/null +++ b/app/src/main/java/com/hkm/dis/DqUtil.java @@ -0,0 +1,20 @@ +package com.hkm.dis; + +import com.hkm.disqus.api.ApiConfig; + +import retrofit.RestAdapter; + +/** + * Created by zJJ on 11/6/2015. + */ +public class DqUtil { + public static ApiConfig genConfig() { + ApiConfig conf = new ApiConfig( + BuildConfig.DISQUS_API_KEY, + BuildConfig.DISQUS_DEFAULT_ACCESS, + RestAdapter.LogLevel.BASIC); + conf.setApiSecret(BuildConfig.DISQUS_SECRET); + conf.setRedirectUri(BuildConfig.DISQUS_REDIRECT_URI); + return conf; + } +} diff --git a/app/src/main/java/com/hkm/dis/applicationbase.java b/app/src/main/java/com/hkm/dis/applicationbase.java deleted file mode 100644 index 05bb984..0000000 --- a/app/src/main/java/com/hkm/dis/applicationbase.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.hkm.dis; - -import android.app.Application; -import android.widget.Toast; - -import com.hkm.disqus.api.ApiClient; -import com.hkm.disqus.api.ApiConfig; -import com.hkm.disqus.api.AuthMgr; -import com.hkm.disqus.api.exception.ApiException; -import com.hkm.disqus.api.model.Response; -import com.hkm.disqus.api.model.posts.Post; -import com.hkm.disqus.api.resources.Posts; - -import java.util.List; - -import retrofit.Callback; -import retrofit.RestAdapter; - -/** - * Created by hesk on 21/5/15. - */ -public class applicationbase extends Application { - - private ApiClient setup; - //public api key - - public final static String applicationKey = "vxtI1dx0za2CziQI4cTKHiwXEf4lxpck218Zh6u62qYW5TRizhQsyPtRItpo48m3"; - // "vxtI1dx0za2CziQI4cTKHiwXEf4lxpck218Zh6u62qYW5TRizhQsyPtRItpo48m3"; - // "9bRtN8ApvO1tSu5l9XOIsmoRNbJtNw7c7rsV7D3O0t4N6PygFLz6keC4sKPXiKEu"; - public final static String default_access = "a2ac478e0508499db6c794a1a8cb2c10"; - public final static String secret = "6BxCbw7u0SUZOT308nCTO9q6Lc9nPNuGsNTOV7GtRrpdk4UdiBeDcMI4wblK62Dq"; - //"uQqUIkGw9ugORF58WdqHYP24eVHSmU5QvzEv2bxXDiKQtPs7kfrBRzcSqBoHBSNu"; - //"6BxCbw7u0SUZOT308nCTO9q6Lc9nPNuGsNTOV7GtRrpdk4UdiBeDcMI4wblK62Dq"; - public final static String redirecturi = "http://hypebeast.com"; - public final static String redirecturidisqushbcallback = "disqus-hb-cb://hypebeast.com"; - public static ApiConfig conf; - public static AuthMgr authmanager; - - @Override - public void onCreate() { - conf = new ApiConfig(applicationKey, default_access, RestAdapter.LogLevel.BASIC); - conf.setApiSecret(secret); - conf.setRedirectUri(redirecturi); - setup = new ApiClient(conf); - authmanager = setup.createAuthenticationManager(this); - } - - public AuthMgr getManager() { - return authmanager; - } - - public ApiConfig getConf() { - return conf; - } - - public void getComments(String comment_id, Callback>> cb) throws ApiException { - setup.createThreads().listPostByIDAsync(comment_id, "hypebeast", cb); - } - - public Posts beginPostTransaction() { - return setup.createPosts(); - } - - public void sso() { - try { - setup.createApplications().listUsage(); - } catch (Exception e) { - Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG); - } - } - -} diff --git a/app/src/main/java/com/hkm/dis/login.java b/app/src/main/java/com/hkm/dis/login.java deleted file mode 100644 index 1b6edc3..0000000 --- a/app/src/main/java/com/hkm/dis/login.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.hkm.dis; - -import android.os.Bundle; - -import com.hkm.disqus.BuildConfig; -import com.hkm.disqus.api.ApiConfig; -import com.hkm.disqus.api.AuthMgr; -import com.hkm.disqus.api.DisqusClient; -import com.hkm.disqus.api.model.oauth2.AccessToken; -import com.hkm.disqus.application.AuthorizeActivity; -import com.hkm.disqus.application.AuthorizeFragment; - -import retrofit.RestAdapter; - - -/** - * Created by hesk on 1/6/15. - */ -public class login extends AuthorizeActivity { - - @Override - protected void statFragmentLogin(Bundle fragment) { - getFragmentManager().beginTransaction().add( - com.hkm.disqus.R.id.fragment_id_authorize, - AuthorizeFragment.newInstance(fragment) - - ).commit(); - } - - - - @Override - protected DisqusClient getClient() { - ApiConfig conf = new ApiConfig( - BuildConfig.DISQUS_API_KEY, - BuildConfig.DISQUS_DEFAULT_ACCESS, - RestAdapter.LogLevel.BASIC); - conf.setApiSecret(BuildConfig.DISQUS_SECRET); - conf.setRedirectUri(BuildConfig.DISQUS_REDIRECT_URI); - return DisqusClient.getInstance(this, conf); - } - - - /* @Override - protected int authorize_layout() { - return R.layout.layoutlogin; - } - - @Override - protected void statFragmentLogin(Bundle fragment) { - getFragmentManager().beginTransaction().add(R.id.fragment_id_a, loginInstance.newInstance(fragment)).commit(); - } - - @Override - public void onFailure() { - super.onFailure(); - } - - @Override - protected AuthMgr getManager() { - return ((applicationbase) getApplication()).getManager(); - } - - @Override - protected ApiConfig getConfiguration() { - return ((applicationbase) getApplication()).getConf(); - } - - - public static class loginInstance extends AuthorizeFragment { - - - - public static loginInstance newInstance(Bundle b) { - loginInstance fragment = new loginInstance(); - fragment.setArguments(b); - return fragment; - } - - - @Override - protected String getNativeCallBack() { - return applicationbase.redirecturidisqushbcallback; - } - - @Override - protected ApiConfig getConf() { - return ((applicationbase) getActivity().getApplication()).getConf(); - } - } -*/ -} diff --git a/app/src/main/java/com/hkm/dis/mainTesting.java b/app/src/main/java/com/hkm/dis/mainTesting.java index de98694..c0eb001 100644 --- a/app/src/main/java/com/hkm/dis/mainTesting.java +++ b/app/src/main/java/com/hkm/dis/mainTesting.java @@ -13,19 +13,15 @@ import android.widget.TextView; import android.widget.Toast; -import com.hkm.disqus.api.ApiConfig; -import com.hkm.disqus.api.AuthMgr; -import com.hkm.disqus.api.DisqusClient; +import com.hkm.disqus.DisqusClient; import com.hkm.disqus.api.exception.ApiException; import com.hkm.disqus.api.model.oauth2.AccessToken; import com.hkm.disqus.api.model.posts.Post; import com.hkm.disqus.application.AuthorizeActivity; -import com.hkm.disqus.application.AuthorizeActivity.*; import java.util.List; import retrofit.Callback; -import retrofit.RestAdapter; import retrofit.RetrofitError; import retrofit.client.Response; @@ -36,84 +32,86 @@ public class mainTesting extends AppCompatActivity { public static String TAG = "gamestarthere"; private TextView tvv; + private String appending_post_content; + private String post_post_id = "1008680"; + private String get_comment_id = "1008680 http://hypebeast.com/?p=1008680"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listlayout); - final EditText ed = (EditText) findViewById(R.id.contentfield); + final EditText edPost = (EditText) findViewById(R.id.contentfield); TintImageView tv = (TintImageView) findViewById(R.id.send); tvv = (TextView) findViewById(R.id.log); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - postPost(ed.getText().toString(), "1008680"); + postPost(edPost.getText().toString(), "1008680"); + edPost.setText(""); } }); + getPost(); } - @Override + protected DisqusClient getClient() { - ApiConfig conf = new ApiConfig( - BuildConfig.DISQUS_API_KEY, - BuildConfig.DISQUS_DEFAULT_ACCESS, - RestAdapter.LogLevel.BASIC); - conf.setApiSecret(BuildConfig.DISQUS_SECRET); - conf.setRedirectUri(BuildConfig.DISQUS_REDIRECT_URI); - return DisqusClient.getInstance(this, conf); + return DisqusClient.getInstance(this, DqUtil.genConfig()); } - private void getPost() { - try { - getBase().getComments("1008680 http://hypebeast.com/?p=1008680", new Callback>>() { - @Override - public void success(com.hkm.disqus.api.model.Response> posts, Response response) { - com.hkm.disqus.api.model.Response> d = posts; - Log.d(TAG, "now its working now"); - addLine(response.getBody() + " and the " + d.data.size() + " items were found"); - } - - @Override - public void failure(RetrofitError error) { - Log.d(TAG, error.getMessage()); - addLine(error.getBody().toString()); - } + private Callback>> response_cb = new Callback>>() { + @Override + public void success(com.hkm.disqus.api.model.Response> posts, Response response) { + addLine("==POST LISTED================================="); + addLine(response.getBody() + " and the " + posts.data.size() + " items were found"); + addLine("=============================================="); + } + @Override + public void failure(RetrofitError error) { + addLine("===ERROR_RETOFIT==============================="); + Log.d(TAG, error.getMessage()); + addLine(error.getMessage()); + addLine("=============================================="); + } + }; + + private Callback> return_cb = new Callback>() { + @Override + public void success(com.hkm.disqus.api.model.Response postResponse, Response response) { + addLine("==Post Success ==============================="); + addLine(response.getBody().toString()); + addLine(postResponse.data.rawMessage); + addLine("=============================================="); + getPost(); + } - }); - } catch (RetrofitError e) { - addLine(e.getMessage()); - } catch (ApiException e) { - addLine(e.getMessage()); + @Override + public void failure(RetrofitError error) { + addLine("===ERROR RETOFIT==============================="); + addLine(error.getUrl().toString() + "\n" + error.getMessage()); + addLine("==============================================="); } - } + }; // "1008680", // "1008680 http://hypebeast.com/?p=1008680", private void postPost(String postmessage, String thread_id) { + if (getClient().getAuthManager().isAuthenticated()) { + getClient().postPost(postmessage, post_post_id, return_cb); + } else { + appending_post_content = postmessage; + getClient().loginNow(this); + } + + } + + private void getPost() { + //"1008680 http://hypebeast.com/?p=1008680" try { - if (getManager().isAuthenticated()) { - getBase().beginPostTransaction().create(postmessage, thread_id, - new Callback>() { - @Override - public void success(com.hkm.disqus.api.model.Response postResponse, Response response) { - addLine(response.getBody().toString()); - } - - @Override - public void failure(RetrofitError error) { - addLine(error.getUrl().toString() + "\n" + error.getMessage()); - addLine("==============================================="); - } - }); - } else { - getClient().loginNow(login.class, this); - } - } catch (RetrofitError e) { - addLine(e.getMessage() + " -- retrofit error"); + getClient().getComments(get_comment_id, response_cb); } catch (ApiException e) { - addLine(e.getMessage()); + e.printStackTrace(); } } @@ -135,12 +133,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { AccessToken token = (AccessToken) data.getExtras().getParcelable(AuthorizeActivity.EXTRA_ACCESS_TOKEN); addLine(token.accessToken); + if (appending_post_content != null) { + postPost(appending_post_content, post_post_id); + appending_post_content = null; + } } } - } - protected void addLine(String newline) { if (tvv != null) { tvv.setText(tvv.getText() + "\n" + newline); @@ -155,7 +155,7 @@ public boolean onOptionsItemSelected(MenuItem item) { getPost(); return true; case R.id.login_page: - getClient().loginNow(login.class, this); + getClient().loginNow(this); return true; default: return super.onOptionsItemSelected(item); diff --git a/disqus/.idea/.name b/disqus/.idea/.name deleted file mode 100644 index 6d76e77..0000000 --- a/disqus/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -disqus \ No newline at end of file diff --git a/disqus/.idea/compiler.xml b/disqus/.idea/compiler.xml deleted file mode 100644 index 9a8b7e5..0000000 --- a/disqus/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - \ No newline at end of file diff --git a/disqus/.idea/copyright/profiles_settings.xml b/disqus/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/disqus/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/disqus/.idea/gradle.xml b/disqus/.idea/gradle.xml deleted file mode 100644 index 543f9a8..0000000 --- a/disqus/.idea/gradle.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/disqus/.idea/libraries/appcompat_v7_22_1_1.xml b/disqus/.idea/libraries/appcompat_v7_22_1_1.xml deleted file mode 100644 index 912a7ee..0000000 --- a/disqus/.idea/libraries/appcompat_v7_22_1_1.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/libraries/disqus_0_1_0.xml b/disqus/.idea/libraries/disqus_0_1_0.xml deleted file mode 100644 index d941851..0000000 --- a/disqus/.idea/libraries/disqus_0_1_0.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/libraries/gson_2_3.xml b/disqus/.idea/libraries/gson_2_3.xml deleted file mode 100644 index f7974c7..0000000 --- a/disqus/.idea/libraries/gson_2_3.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/libraries/okhttp_2_3_0.xml b/disqus/.idea/libraries/okhttp_2_3_0.xml deleted file mode 100644 index e0ed48a..0000000 --- a/disqus/.idea/libraries/okhttp_2_3_0.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/libraries/okhttp_urlconnection_2_2_0.xml b/disqus/.idea/libraries/okhttp_urlconnection_2_2_0.xml deleted file mode 100644 index b00393f..0000000 --- a/disqus/.idea/libraries/okhttp_urlconnection_2_2_0.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/libraries/okio_1_3_0.xml b/disqus/.idea/libraries/okio_1_3_0.xml deleted file mode 100644 index 93a99cb..0000000 --- a/disqus/.idea/libraries/okio_1_3_0.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/libraries/picasso_2_5_0.xml b/disqus/.idea/libraries/picasso_2_5_0.xml deleted file mode 100644 index 7ad83bd..0000000 --- a/disqus/.idea/libraries/picasso_2_5_0.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/libraries/realm_android_0_80_0.xml b/disqus/.idea/libraries/realm_android_0_80_0.xml deleted file mode 100644 index 7ce9e3d..0000000 --- a/disqus/.idea/libraries/realm_android_0_80_0.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/libraries/retrofit_1_7_1.xml b/disqus/.idea/libraries/retrofit_1_7_1.xml deleted file mode 100644 index 5acb85d..0000000 --- a/disqus/.idea/libraries/retrofit_1_7_1.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/libraries/support_annotations_22_1_1.xml b/disqus/.idea/libraries/support_annotations_22_1_1.xml deleted file mode 100644 index ef92029..0000000 --- a/disqus/.idea/libraries/support_annotations_22_1_1.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/libraries/support_v4_22_1_1.xml b/disqus/.idea/libraries/support_v4_22_1_1.xml deleted file mode 100644 index 7cc2b95..0000000 --- a/disqus/.idea/libraries/support_v4_22_1_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/misc.xml b/disqus/.idea/misc.xml deleted file mode 100644 index 0864d35..0000000 --- a/disqus/.idea/misc.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/modules.xml b/disqus/.idea/modules.xml deleted file mode 100644 index 0b228d4..0000000 --- a/disqus/.idea/modules.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/disqus/.idea/workspace.xml b/disqus/.idea/workspace.xml deleted file mode 100644 index 3f02544..0000000 --- a/disqus/.idea/workspace.xml +++ /dev/null @@ -1,2888 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - localhost - 5050 - - - - - $USER_HOME$/.subversion - - - - - 1432199733585 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/disqus/disqus.iml b/disqus/disqus.iml index 81424f5..5be6897 100644 --- a/disqus/disqus.iml +++ b/disqus/disqus.iml @@ -89,20 +89,20 @@ - - - - - - - - - + + + + + + + + - + + \ No newline at end of file diff --git a/disqus/src/main/AndroidManifest.xml b/disqus/src/main/AndroidManifest.xml index 36bb87c..b695431 100644 --- a/disqus/src/main/AndroidManifest.xml +++ b/disqus/src/main/AndroidManifest.xml @@ -4,18 +4,9 @@ - - - - - - - - - - - + diff --git a/disqus/src/main/java/com/hkm/disqus/api/DisqusClient.java b/disqus/src/main/java/com/hkm/disqus/DisqusClient.java similarity index 67% rename from disqus/src/main/java/com/hkm/disqus/api/DisqusClient.java rename to disqus/src/main/java/com/hkm/disqus/DisqusClient.java index 4974208..212c43b 100644 --- a/disqus/src/main/java/com/hkm/disqus/api/DisqusClient.java +++ b/disqus/src/main/java/com/hkm/disqus/DisqusClient.java @@ -1,16 +1,18 @@ -package com.hkm.disqus.api; +package com.hkm.disqus; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import com.hkm.disqus.api.ApiClient; +import com.hkm.disqus.api.ApiConfig; +import com.hkm.disqus.api.AuthTokenServiceManager; import com.hkm.disqus.api.exception.ApiException; import com.hkm.disqus.api.model.Response; import com.hkm.disqus.api.model.posts.Post; +import com.hkm.disqus.api.resources.AccessTokenService; import com.hkm.disqus.application.AuthorizeActivity; -import com.squareup.picasso.LruCache; -import com.squareup.picasso.OkHttpDownloader; -import com.squareup.picasso.Picasso; import java.util.List; @@ -22,8 +24,7 @@ public class DisqusClient extends ApiClient { public static final int authorization_intent_id = 9392; private Context mcontent; - private static AuthMgr instance_auth; - + private static AuthTokenServiceManager instance_am; private static DisqusClient main_instance; /** @@ -39,6 +40,10 @@ public static DisqusClient getInstance(Context c, ApiConfig conf) { return main_instance; } + public static DisqusClient getInstance() throws NullPointerException { + return main_instance; + } + /** * THe content * @@ -48,13 +53,13 @@ public static DisqusClient getInstance(Context c, ApiConfig conf) { public DisqusClient(ApiConfig config, Context context) { super(config); mcontent = context; - if (instance_auth == null) { - instance_auth = createAuthenticationManager(context); + if (instance_am == null) { + instance_am = createAuthenticationManager(context); } } - public AuthMgr getAuthManager() { - return instance_auth; + public AuthTokenServiceManager getAuthManager() { + return instance_am; } public void getComments(String comment_id, Callback> cbp } } - public void loginNow(final Class login_class, AppCompatActivity activity) { - Intent in = new Intent(activity, login_class); + public void loginNow(Activity activity) { + Intent in = new Intent(activity, AuthorizeActivity.class); in.putExtras(getConfiguration().getLogInBundle()); activity.startActivityForResult(in, authorization_intent_id); } - - /** - * create and return picasso - * - * @return the te ciea - */ - public Picasso providesPicasso() { - return new Picasso.Builder(mcontent) - .downloader(new OkHttpDownloader(mcontent)) - .memoryCache(new LruCache(mcontent)) - .build(); - } } diff --git a/disqus/src/main/java/com/hkm/disqus/api/ApiClient.java b/disqus/src/main/java/com/hkm/disqus/api/ApiClient.java index 0d6988a..eab7442 100755 --- a/disqus/src/main/java/com/hkm/disqus/api/ApiClient.java +++ b/disqus/src/main/java/com/hkm/disqus/api/ApiClient.java @@ -46,9 +46,6 @@ import com.hkm.disqus.api.resources.Users; import com.hkm.disqus.api.resources.notes.Templates; import com.hkm.disqus.api.retrofitworker.Interceptor; -import com.squareup.picasso.LruCache; -import com.squareup.picasso.OkHttpDownloader; -import com.squareup.picasso.Picasso; import retrofit.ErrorHandler; import retrofit.RequestInterceptor; @@ -71,14 +68,14 @@ public class ApiClient { /** * User agent */ - private static final String USER_AGENT = "Disqus Android/0.1"; + private static final String USER_AGENT = "Disqus Android/1.1"; /** * Rest adapter */ private RestAdapter mAdapter; /** - * login adapter + * disqusloginactivityframelayout adapter */ private RestAdapter mLoginAdapter; /** @@ -120,7 +117,7 @@ public Throwable handleError(RetrofitError cause) { } }; - // Build RestAdapter for after login + // Build RestAdapter for after disqusloginactivityframelayout mAdapter = new RestAdapter.Builder() .setEndpoint(BASE_URL) .setLogLevel(config != null ? config.getLogLevel() : RestAdapter.LogLevel.NONE) @@ -309,8 +306,8 @@ private AccessTokenService createTokenService() { return mLoginAdapter.create(AccessTokenService.class); } - public AuthMgr createAuthenticationManager(Context contex) { - return new AuthMgr(contex, createTokenService(), _config); + public AuthTokenServiceManager createAuthenticationManager(Context contex) { + return new AuthTokenServiceManager(contex, createTokenService(), _config); } public ApiConfig getConfiguration() { diff --git a/disqus/src/main/java/com/hkm/disqus/api/AuthMgr.java b/disqus/src/main/java/com/hkm/disqus/api/AuthTokenServiceManager.java similarity index 96% rename from disqus/src/main/java/com/hkm/disqus/api/AuthMgr.java rename to disqus/src/main/java/com/hkm/disqus/api/AuthTokenServiceManager.java index aacd475..1dd411e 100644 --- a/disqus/src/main/java/com/hkm/disqus/api/AuthMgr.java +++ b/disqus/src/main/java/com/hkm/disqus/api/AuthTokenServiceManager.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.support.annotation.Nullable; import android.util.Log; import com.hkm.disqus.DisqusConstants; @@ -26,7 +27,7 @@ /** * Created by hesk on 5/6/15. */ -public class AuthMgr { +public class AuthTokenServiceManager { private static final String PREF_AUTH = "AuthManager.Preferences"; private static final String PREF_TOKEN = ".access_token"; private static final String PREF_EXPIRE = ".expires_in"; @@ -49,7 +50,7 @@ public void removeListener(AuthenticationListener listener) { } - public AuthMgr(Context context, AccessTokenService accesstokenservice, ApiConfig configurations) { + public AuthTokenServiceManager(Context context, AccessTokenService accesstokenservice, ApiConfig configurations) { appContext = context; config = configurations; accessTokenService = accesstokenservice; @@ -60,7 +61,7 @@ public AuthMgr(Context context, AccessTokenService accesstokenservice, ApiConfig } } - public void authorizeAsync(final String code) { + public void authorizeAsync(@Nullable final String code) throws NullPointerException{ if (code != null) { if (DisqusConstants.apiVersion == 1) { @@ -165,7 +166,7 @@ public void success(AccessToken accessToken, Response response) { if (isLogin) { for (AuthenticationListener listener : listeners) { - listener.onLogin(accessToken); // notify listeners about login. + listener.onLogin(accessToken); // notify listeners about disqusloginactivityframelayout. //currentUserManager.getCurrentUser(null, true); // force a network call to get current user and add to memory. } diff --git a/disqus/src/main/java/com/hkm/disqus/api/RefreshTokenBroadcastReceiver.java b/disqus/src/main/java/com/hkm/disqus/api/RefreshTokenBroadcastReceiver.java index 5273444..d340c6c 100644 --- a/disqus/src/main/java/com/hkm/disqus/api/RefreshTokenBroadcastReceiver.java +++ b/disqus/src/main/java/com/hkm/disqus/api/RefreshTokenBroadcastReceiver.java @@ -9,7 +9,7 @@ public class RefreshTokenBroadcastReceiver extends BroadcastReceiver { - private AuthMgr authManager; + private AuthTokenServiceManager authManager; public RefreshTokenBroadcastReceiver() { //DisqusSdkProvider.getInstance().getObjectGraph().inject(this); diff --git a/disqus/src/main/java/com/hkm/disqus/application/AuthorizationFragment.java b/disqus/src/main/java/com/hkm/disqus/application/AuthorizationFragment.java index 7c01f53..40b61eb 100644 --- a/disqus/src/main/java/com/hkm/disqus/application/AuthorizationFragment.java +++ b/disqus/src/main/java/com/hkm/disqus/application/AuthorizationFragment.java @@ -4,23 +4,26 @@ import android.net.Uri; import android.os.Bundle; import android.support.annotation.Nullable; -import android.support.annotation.StringRes; +import android.support.v4.view.ViewCompat; import android.util.Log; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import android.webkit.WebView; +import com.hkm.disqus.DisqusClient; import com.hkm.disqus.DisqusConstants; -import com.hkm.disqus.api.DisqusClient; +import com.hkm.disqus.api.ApiConfig; import com.hkm.ezwebview.Util.Fx9C; import com.hkm.ezwebview.app.BasicWebViewNormal; import com.hkm.ezwebview.webviewclients.PaymentClient; +import retrofit.RestAdapter; + /** * Created by hesk on 6/11/15. */ public class AuthorizationFragment extends BasicWebViewNormal { + + public static AuthorizationFragment B(final Bundle b) { final AuthorizationFragment t = new AuthorizationFragment(); t.setArguments(b); @@ -32,13 +35,35 @@ public static Bundle ScopeBundle(@Nullable String apikey, @Nullable String redirect_uri, @Nullable String secret) { final Bundle n = new Bundle(); - n.putString(ARG_API_KEY, apikey); - n.putString(ARG_SCOPES, scope); - n.putString(ARG_REDIRECT_URI, redirect_uri); - n.putString(ARG_SECRET, secret); + n.putString(AuthorizeActivity.EXTRA_API_KEY, apikey); + n.putString(AuthorizeActivity.EXTRA_SCOPES, scope); + n.putString(AuthorizeActivity.EXTRA_REDIRECT_URI, redirect_uri); + n.putString(AuthorizeActivity.EXTRA_SECRET, secret); + return n; + } + + public static Bundle bundleConfig(@Nullable String apikey, + @Nullable String access_default, + @Nullable String redirect_uri, + @Nullable String secret) { + final Bundle n = new Bundle(); + n.putString(AuthorizeActivity.EXTRA_API_KEY, apikey); + n.putString(AuthorizeActivity.EXTRA_DEFAULT_ACCESS, access_default); + n.putString(AuthorizeActivity.EXTRA_REDIRECT_URI, redirect_uri); + n.putString(AuthorizeActivity.EXTRA_SECRET, secret); return n; } + public static ApiConfig genConfig(Bundle bundle) { + ApiConfig conf = new ApiConfig( + bundle.getString(AuthorizeActivity.EXTRA_API_KEY), + bundle.getString(AuthorizeActivity.EXTRA_DEFAULT_ACCESS), + RestAdapter.LogLevel.BASIC); + conf.setApiSecret(bundle.getString(AuthorizeActivity.EXTRA_SECRET)); + conf.setRedirectUri(bundle.getString(AuthorizeActivity.EXTRA_REDIRECT_URI)); + return conf; + } + /** * on press */ @@ -46,15 +71,8 @@ public static Bundle ScopeBundle(@Nullable String apikey, /** * Logging tag */ - protected static final String TAG = AuthorizeFragment.class.getName(); + protected static final String TAG = "AuthorizLog"; - /** - * Arguments - */ - protected static final String ARG_API_KEY = "api_key"; - protected static final String ARG_SCOPES = "scope"; - protected static final String ARG_REDIRECT_URI = "redirect_uri"; - protected static final String ARG_SECRET = "secret"; protected ACTION maction; @@ -83,7 +101,7 @@ public static Bundle ScopeBundle(@Nullable String apikey, // private AuthorizeListener mListener; /** - * A {@link WebView} to display the Disqus login + * A {@link WebView} to display the Disqus disqusloginactivityframelayout */ private WebView mWebView; private boolean isDialogShown = false; @@ -93,17 +111,17 @@ enum ACTION { } protected void LoadConfig() { - if (getArguments().containsKey(ARG_API_KEY)) { - mApiKey = getArguments().getString(ARG_API_KEY); + if (getArguments().containsKey(AuthorizeActivity.EXTRA_API_KEY)) { + mApiKey = getArguments().getString(AuthorizeActivity.EXTRA_API_KEY); } - if (getArguments().containsKey(ARG_SCOPES)) { - mScopes = getArguments().getStringArray(ARG_SCOPES); + if (getArguments().containsKey(AuthorizeActivity.EXTRA_SCOPES)) { + mScopes = getArguments().getStringArray(AuthorizeActivity.EXTRA_SCOPES); } - if (getArguments().containsKey(ARG_REDIRECT_URI)) { - mRedirectUri = getArguments().getString(ARG_REDIRECT_URI); + if (getArguments().containsKey(AuthorizeActivity.EXTRA_REDIRECT_URI)) { + mRedirectUri = getArguments().getString(AuthorizeActivity.EXTRA_REDIRECT_URI); } - if (getArguments().containsKey(ARG_SECRET)) { - mSecret = getArguments().getString(ARG_SECRET); + if (getArguments().containsKey(AuthorizeActivity.EXTRA_SECRET)) { + mSecret = getArguments().getString(AuthorizeActivity.EXTRA_SECRET); } } @@ -127,17 +145,12 @@ private String getScopes() { public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); LoadConfig(); - setup_token_view(new AuthorizationClient(getActivity(), block, mRedirectUri)); - } - - - protected void setup_token_view(T clientLogic) { - Uri request_access_token_path_final = AuthorizeUtils.buildAuthorizeUri(mApiKey, getScopes(), mRedirectUri); String msg = "Loading authorize url: " + request_access_token_path_final.toString(); Log.d(TAG, msg); + final AuthorizationClient mAth = new AuthorizationClient(getActivity(), block); Fx9C.setup_payment_gateway( - clientLogic, + mAth, framer, block, betterCircleBar, @@ -146,65 +159,52 @@ protected void setup_token_view(T clientLogic) { 1600); } - private static class AuthorizationClient extends PaymentClient { - - private String redirect; + protected void load() { + if (betterCircleBar == null) return; + betterCircleBar.setVisibility(View.INVISIBLE); + ViewCompat.animate(betterCircleBar).alpha(1.0F); + } - public static AuthorizationClient with(Activity context, WebView mview, String redirect) { - final AuthorizationClient pay = new AuthorizationClient(context, mview, redirect); - return pay; - } + private class AuthorizationClient extends PaymentClient { @Override protected void triggerNative(Uri trigger_url) { - super.triggerNative(trigger_url); + try { + DisqusClient.getInstance().getAuthManager().authorizeAsync(trigger_url.getQueryParameter("code")); + } catch (NullPointerException e) { + + } } @Override protected boolean interceptUrl(WebView view, String url) { - final String coderequeststart = redirect + DisqusConstants.authorizeCode; Log.d(TAG, "base change: " + url); - - if (url.startsWith(coderequeststart)) { - Log.d("", "Got Url " + url); - Uri uri = Uri.parse(url); - final String code = uri.getQueryParameter("code"); - Log.d(TAG, "Acquiring Code: " + code); - - // DisqusClient - authentication_manager.authorizeAsync(code); - - - // mWebView.postUrl(DisqusConstants.AUTHORIZE_ACCESS_TOKEN, EncodingUtils.getBytes(AuthorizeUtils.buildCodeRequestJustBody(code, mApiKey, mSecret, mRedirectUri), "BASE64")); - - - return true; - } else if (url.startsWith(allowBUttonPressUrl)) { - dislogProcessNotice(); - //continue - } else if (url.startsWith(mRedirectUri)) { - // Get fragment from url - Log.d(TAG, "Acquiring Processing redirect: " + url); - // mListener.onSuccess(AuthorizeUtils.getDataToken(url)); - return true; + Uri uri = Uri.parse(url); + try { + if (!uri.getQueryParameter("code").equalsIgnoreCase("")) { + triggerNative(Uri.parse(url)); + return true; + } + + if (url.startsWith(authURI)) { + load(); + return false; + } + } catch (NullPointerException e) { + Log.d(TAG, "no key is found change: " + url); + return false; + } catch (UnsupportedOperationException e) { + Log.d(TAG, "UnsupportedOperationException change: " + url); + return false; + } catch (Exception e) { + Log.d(TAG, "Other things change: " + url); + return false; } return false; } - public AuthorizationClient(Activity context, WebView fmWebView, String redirect) { + public AuthorizationClient(Activity context, WebView fmWebView) { super(context, fmWebView); - this.redirect = redirect; - allow = new String[]{ - authURI, - - }; - // nativefunctions = new String[]{ - //start native app - // domain_start, - // domain_start_insecure - - // }; - } diff --git a/disqus/src/main/java/com/hkm/disqus/application/AuthorizeActivity.java b/disqus/src/main/java/com/hkm/disqus/application/AuthorizeActivity.java index 7681357..47ab73d 100644 --- a/disqus/src/main/java/com/hkm/disqus/application/AuthorizeActivity.java +++ b/disqus/src/main/java/com/hkm/disqus/application/AuthorizeActivity.java @@ -5,24 +5,21 @@ import android.app.DialogFragment; import android.content.DialogInterface; import android.content.Intent; -import android.net.Uri; import android.os.Bundle; import android.support.annotation.LayoutRes; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.util.Log; -import android.widget.Toast; import com.hkm.disqus.R; -import com.hkm.disqus.api.ApiConfig; -import com.hkm.disqus.api.AuthMgr; -import com.hkm.disqus.api.DisqusClient; +import com.hkm.disqus.api.AuthTokenServiceManager; +import com.hkm.disqus.DisqusClient; import com.hkm.disqus.api.model.oauth2.AccessToken; /** * Created by hesk on 21/5/15. */ -public abstract class AuthorizeActivity extends AppCompatActivity implements AuthorizeFragment.AuthorizeListener, AuthMgr.AuthenticationListener { +public class AuthorizeActivity extends AppCompatActivity implements AuthTokenServiceManager.AuthenticationListener { public static final String TAG = "authorization act"; /** * Extras that should be passed in the {@link Intent} @@ -36,19 +33,27 @@ public abstract class AuthorizeActivity extends AppCompatActivity implements Aut */ public static final String EXTRA_ACCESS_TOKEN = "access_token"; public static final String EXTRA_SECRET = "secret"; + public static final String EXTRA_DEFAULT_ACCESS = "default"; + @LayoutRes protected int authorize_layout() { - return R.layout.login; + int e = R.layout.disqusloginactivityframelayout; + return e; } - protected abstract DisqusClient getClient(); - + protected DisqusClient getClient() { + return DisqusClient.getInstance(this, AuthorizationFragment.genConfig(getIntent().getExtras())); + } - protected abstract void statFragmentLogin(Bundle fragmentextras); + protected void statFragmentLogin(Bundle fragmentextras) { + getFragmentManager().beginTransaction().add( + R.id.disqus_fragment_id_authorize, + AuthorizationFragment.B(fragmentextras) + ).commit(); + } // private Binder binder; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -65,29 +70,28 @@ protected void onCreate(Bundle savedInstanceState) { // binder = ((BinderProvider) getParentFragment()).createBinder(this); } - @Override - public void onSuccess(AccessToken accessToken) { - // Create a result intent - Intent data = new Intent(); - data.putExtra(EXTRA_ACCESS_TOKEN, accessToken); - setResult(RESULT_OK, data); - finish(); - } - - @Override - public void onFailure() { - Toast.makeText(this, getResources().getString(R.string.failurelogin), Toast.LENGTH_LONG); - setResult(RESULT_CANCELED); - finish(); - } - + /* @Override + public void onSuccess(AccessToken accessToken) { + // Create a result intent + Intent data = new Intent(); + data.putExtra(EXTRA_ACCESS_TOKEN, accessToken); + setResult(RESULT_OK, data); + finish(); + } + + @Override + public void onFailure() { + Toast.makeText(this, getResources().getString(R.string.failurelogin), Toast.LENGTH_LONG); + setResult(RESULT_CANCELED); + finish(); + } + */ @Override public void onBackPressed() { setResult(RESULT_CANCELED); super.onBackPressed(); } - @Override public void onStart() { super.onStart(); @@ -140,7 +144,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { builder.setMessage(this.m) .setPositiveButton(R.string.donesuccess, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - onFailure(); + // onFailure(); onLoginFailed(m); } }); diff --git a/disqus/src/main/java/com/hkm/disqus/application/AuthorizeFragment.java b/disqus/src/main/java/com/hkm/disqus/application/AuthorizeFragment.java deleted file mode 100644 index 10d5fa1..0000000 --- a/disqus/src/main/java/com/hkm/disqus/application/AuthorizeFragment.java +++ /dev/null @@ -1,212 +0,0 @@ -package com.hkm.disqus.application; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.app.Dialog; -import android.app.DialogFragment; -import android.app.Fragment; -import android.app.ProgressDialog; -import android.content.DialogInterface; -import android.net.Uri; -import android.os.Bundle; -import android.support.v7.app.AlertDialog; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.webkit.WebView; -import android.webkit.WebViewClient; - -import com.hkm.disqus.DisqusConstants; -import com.hkm.disqus.R; -import com.hkm.disqus.api.ApiConfig; -import com.hkm.disqus.api.AuthMgr; -import com.hkm.disqus.api.model.oauth2.AccessToken; - - -/** - * Created by hesk on 21/5/15. - */ -public abstract class AuthorizeFragment extends Fragment { - /** - * on press - */ - private static final String allowBUttonPressUrl = "https://disqus.com/api/oauth/2.0/grant/"; - /** - * Logging tag - */ - protected static final String TAG = AuthorizeFragment.class.getName(); - - /** - * Arguments - */ - protected static final String ARG_API_KEY = "api_key"; - protected static final String ARG_SCOPES = "scope"; - protected static final String ARG_REDIRECT_URI = "redirect_uri"; - protected static final String ARG_SECRET = "secret"; - - protected ACTION maction; - - enum ACTION { - REFRESH_TOKEN, STEP1, STEP2 - } - - /** - * The Disqus API key - */ - private String mApiKey; - /** - * The Disqus secret id - */ - private String mSecret; - - /** - * Scopes - */ - private String[] mScopes; - - /** - * Authorize redirect URI - */ - private String mRedirectUri; - - /** - * Authorization listener - */ - // private AuthorizeListener mListener; - - /** - * A {@link WebView} to display the Disqus login - */ - private WebView mWebView; - private boolean isDialogShown = false; - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - mWebView = (WebView) view.findViewById(R.id.disqus_login_webview); - routeAuth(); - isDialogShown = false; - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.loginwebview, container, false); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - if (getArguments().containsKey(ARG_API_KEY)) { - mApiKey = getArguments().getString(ARG_API_KEY); - } - if (getArguments().containsKey(ARG_SCOPES)) { - mScopes = getArguments().getStringArray(ARG_SCOPES); - } - if (getArguments().containsKey(ARG_REDIRECT_URI)) { - mRedirectUri = getArguments().getString(ARG_REDIRECT_URI); - } - if (getArguments().containsKey(ARG_SECRET)) { - mSecret = getArguments().getString(ARG_SECRET); - } - } - - //automatically attached; - private AuthMgr authentication_manager; - private AuthorizeActivity getListenercontext; - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - try { - getListenercontext = (AuthorizeActivity) activity; - // mListener = (AuthorizeListener) activity; - authentication_manager = getListenercontext.getManager(); - } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + " must implement AuthorizeCallback"); - } - } - - protected abstract String getNativeCallBack(); - - protected abstract ApiConfig getConf(); - - private void dislogProcessNotice() { - if (!isDialogShown) { - ProgressDialog.show(getActivity(), "one moment", "progressing"); - isDialogShown = true; - } - } - - private boolean usewebview = false; - - private void routeAuth() { - // Setup custom client to catch the redirect - mWebView.setWebViewClient(new WebViewClient() { - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - final String coderequeststart = mRedirectUri + DisqusConstants.authorizeCode; - Log.d(TAG, "base change: " + url); - if (url.startsWith(coderequeststart)) { - Log.d("", "Got Url " + url); - Uri uri = Uri.parse(url); - final String code = uri.getQueryParameter("code"); - Log.d(TAG, "Acquiring Code: " + code); - - - authentication_manager.authorizeAsync(code); - - - // mWebView.postUrl(DisqusConstants.AUTHORIZE_ACCESS_TOKEN, EncodingUtils.getBytes(AuthorizeUtils.buildCodeRequestJustBody(code, mApiKey, mSecret, mRedirectUri), "BASE64")); - - - return true; - } else if (url.startsWith(allowBUttonPressUrl)) { - dislogProcessNotice(); - //continue - } else if (url.startsWith(mRedirectUri)) { - // Get fragment from url - Log.d(TAG, "Acquiring Processing redirect: " + url); - // mListener.onSuccess(AuthorizeUtils.getDataToken(url)); - return true; - } - return super.shouldOverrideUrlLoading(view, url); - } - }); - - Uri uri = AuthorizeUtils.buildAuthorizeUri(mApiKey, getScopes(), mRedirectUri); - String fftoken = "Loading authorize url: " + uri.toString(); - Log.d(TAG, fftoken); - mWebView.loadUrl(uri.toString()); - } - - - /** - * Load authorize url - * - * @return the string - */ - private String getScopes() { - String scope; - try { - scope = AuthorizeUtils.buildScope(mScopes); - } catch (Exception e) { - scope = "read,write"; - } - return scope; - } - // abstract protected void posttextview(String something); - - /** - * Listener interface, must be implemented by calling activity - */ - public interface AuthorizeListener { - - void onSuccess(AccessToken accessToken); - - void onFailure(); - } - - -} \ No newline at end of file diff --git a/disqus/src/main/java/com/hkm/disqus/application/PostCommentFragment.java b/disqus/src/main/java/com/hkm/disqus/application/PostCommentFragment.java new file mode 100644 index 0000000..3e6c855 --- /dev/null +++ b/disqus/src/main/java/com/hkm/disqus/application/PostCommentFragment.java @@ -0,0 +1,89 @@ +package com.hkm.disqus.application; + +import android.app.Fragment; +import android.content.Intent; +import android.util.Log; +import android.widget.Toast; + +import com.hkm.disqus.DisqusClient; +import com.hkm.disqus.api.ApiConfig; +import com.hkm.disqus.api.exception.ApiException; +import com.hkm.disqus.api.model.Response; +import com.hkm.disqus.api.model.oauth2.AccessToken; +import com.hkm.disqus.api.model.posts.Post; + +import java.util.List; + +import retrofit.Callback; +import retrofit.RetrofitError; + +/** + * Created by zJJ on 11/7/2015. + */ +public abstract class PostCommentFragment extends Fragment { + public static String TAG = "debugDisqusComment"; + + protected abstract ApiConfig getConfiguration(); + + /** + * debug log line + * + * @param newline the string + */ + protected void addLine(String newline) { + + } + + private Callback>> response_cb = new Callback>>() { + @Override + public void success(com.hkm.disqus.api.model.Response> posts, retrofit.client.Response response) { + com.hkm.disqus.api.model.Response> d = posts; + Log.d(TAG, "now its working now"); + addLine(response.getBody() + " and the " + d.data.size() + " items were found"); + } + + @Override + public void failure(RetrofitError error) { + Log.d(TAG, error.getMessage()); + addLine(error.getBody().toString()); + } + }; + + private Callback> return_cb = new Callback>() { + @Override + public void success(com.hkm.disqus.api.model.Response postResponse, retrofit.client.Response response) { + addLine(response.getBody().toString()); + } + + @Override + public void failure(RetrofitError error) { + addLine(error.getUrl().toString() + "\n" + error.getMessage()); + addLine("==============================================="); + } + }; + + + private DisqusClient getClient() { + return DisqusClient.getInstance(getActivity(), getConfiguration()); + } + + + protected void postPost(String postmessage, String thread_id) { + if (getClient().getAuthManager().isAuthenticated()) { + getClient().postPost(postmessage, thread_id, return_cb); + } else { + getClient().loginNow(getActivity()); + } + + } + + protected void getPost(String threadID) { + //"1008680 http://hypebeast.com/?p=1008680" + try { + getClient().getComments(threadID, response_cb); + } catch (ApiException e) { + e.printStackTrace(); + } + } + +} diff --git a/disqus/src/main/java/com/hkm/disqus/application/WebviewIntercept.java b/disqus/src/main/java/com/hkm/disqus/application/WebviewIntercept.java deleted file mode 100644 index 87eff2f..0000000 --- a/disqus/src/main/java/com/hkm/disqus/application/WebviewIntercept.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.hkm.disqus.application; - -import android.annotation.TargetApi; -import android.content.Intent; -import android.content.res.AssetManager; -import android.net.Uri; -import android.os.Build; -import android.support.v7.app.AppCompatActivity; -import android.util.Log; -import android.webkit.WebResourceRequest; -import android.webkit.WebResourceResponse; -import android.webkit.WebView; -import android.webkit.WebViewClient; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Created by hesk on 3/6/15. - * WebviewIntercept - * currently we dont use it in the code base - * App.Compat - */ -@Deprecated -public class WebviewIntercept extends WebViewClient { - private final AppCompatActivity activity; - public static final String LOG_TAG = "webviewnow"; - - private UrlCache urlCache = null; - - public WebviewIntercept(AppCompatActivity a) { - this.activity = a; - this.urlCache = new UrlCache(a); - this.urlCache.register("http://tutorials.jenkov.com/", "tutorials-jenkov-com.html", - "text/html", "UTF-8", 5 * UrlCache.ONE_MINUTE); - } - - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - if (url.indexOf("jenkov.com") > -1) return false; - - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - activity.startActivity(intent); - return true; - } - - - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - @Override - public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest rs) { - if (rs.getUrl().toString().startsWith("http://tutorials.jenkov.com/images/logo.png")) { - return loadFromAssets(rs.getUrl().toString(), "images/logo.png", "image/png", ""); - } - return this.urlCache.load(rs.getUrl().toString()); - } - - private WebResourceResponse loadFromAssets( - String url, String assetPath, - String mimeType, String encoding - ) { - - AssetManager assetManager = this.activity.getAssets(); - InputStream input = null; - try { - Log.d(LOG_TAG, "Loading from assets: " + assetPath); - - - input = assetManager.open("/images/logo.png"); - WebResourceResponse response = - new WebResourceResponse(mimeType, encoding, input); - - return response; - } catch (IOException e) { - Log.e("WEB-APP", "Error loading " + assetPath + " from assets: " + - e.getMessage(), e); - } - return null; - } -} diff --git a/disqus/src/main/java/com/hkm/disqus/application/authorizedcallback.java b/disqus/src/main/java/com/hkm/disqus/application/authorizedcallback.java deleted file mode 100644 index 7d57cf8..0000000 --- a/disqus/src/main/java/com/hkm/disqus/application/authorizedcallback.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.hkm.disqus.application; - -import android.content.Intent; -import android.net.Uri; -import android.support.v7.app.AppCompatActivity; -import android.util.Log; - -/** - * currently we dont use it in the code - * This class will be removed in the next version - * Created by hesk on 2/6/15. - */ -@Deprecated -public class authorizedcallback extends AppCompatActivity { - public static final String CALLBACK_URL = "disqus-hb-cb:///"; - public static final String TAG = "nowdisqus"; - - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - dealWithTwitterResponse(intent); - } - - private void dealWithTwitterResponse(Intent intent) { - Uri uri = intent.getData(); - System.out.println("URI=" + uri); - if (uri != null && uri.toString().startsWith(CALLBACK_URL)) { - String oauthVerifier = uri.getQueryParameter("oauth_verifier"); - //authoriseNewUser(oauthVerifier); - - Log.d(TAG, uri.toString()); - } - } -} diff --git a/disqus/src/main/res/layout/login.xml b/disqus/src/main/res/layout/disqusloginactivityframelayout.xml similarity index 60% rename from disqus/src/main/res/layout/login.xml rename to disqus/src/main/res/layout/disqusloginactivityframelayout.xml index 16c0a71..3cf6fc5 100644 --- a/disqus/src/main/res/layout/login.xml +++ b/disqus/src/main/res/layout/disqusloginactivityframelayout.xml @@ -4,13 +4,13 @@ android:layout_height="match_parent"> + android:layout_height="25dp" /> - + android:layout_below="@id/disqus_status_bar_login" /> \ No newline at end of file diff --git a/disqus/src/main/res/raw/embed b/disqus/src/main/res/raw/embed deleted file mode 100644 index effc9aa..0000000 --- a/disqus/src/main/res/raw/embed +++ /dev/null @@ -1,12 +0,0 @@ - -
- - - \ No newline at end of file diff --git a/disqus/src/main/res/raw/embeddisqus b/disqus/src/main/res/raw/embeddisqus deleted file mode 100644 index e4a84ff..0000000 --- a/disqus/src/main/res/raw/embeddisqus +++ /dev/null @@ -1,15 +0,0 @@ - -
- - - \ No newline at end of file diff --git a/disqus/src/main/res/values/ids.xml b/disqus/src/main/res/values/ids.xml index 55344e5..a2eeb5d 100644 --- a/disqus/src/main/res/values/ids.xml +++ b/disqus/src/main/res/values/ids.xml @@ -1,3 +1,5 @@ + + \ No newline at end of file