diff --git a/app/build.gradle b/app/build.gradle index a0420fa..f6d9646 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,25 +1,26 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) android { compileSdkVersion 25 - buildToolsVersion "25" + buildToolsVersion "25.0.1" dexOptions { javaMaxHeapSize "2048M" } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } +// compileOptions { +// sourceCompatibility JavaVersion.VERSION_1_8 +// targetCompatibility JavaVersion.VERSION_1_8 +// } defaultConfig { applicationId "moe.tlaster.openween" minSdkVersion 21 targetSdkVersion 25 versionCode 1 versionName "0.89757.3" - jackOptions { - enabled true - } +// jackOptions { +// enabled true +// } resValue "string", "tray__authority", "${applicationId}.tray" manifestPlaceholders = [HOCKEYAPP_APP_ID: properties.getProperty("HOCKEYAPP_APP_ID")] @@ -30,19 +31,22 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') - compile('com.mikepenz:materialdrawer:5.7.0@aar') { + compile('com.mikepenz:materialdrawer:5.8.0@aar') { transitive = true } compile group: 'org.ocpsoft.prettytime', name: 'prettytime', version: '4.0.1.Final' - compile 'com.android.support:cardview-v7:25.0.0' - compile 'com.android.support:gridlayout-v7:25.0.0' - compile 'com.android.support:appcompat-v7:25.0.0' - compile 'com.android.support:recyclerview-v7:25.0.0' - compile 'com.android.support:design:25.0.0' + compile 'com.android.support:cardview-v7:25.0.1' + compile 'com.android.support:gridlayout-v7:25.0.1' + compile 'com.android.support:appcompat-v7:25.0.1' + compile 'com.android.support:recyclerview-v7:25.0.1' + compile 'com.android.support:design:25.0.1' compile 'com.google.code.gson:gson:2.7' compile 'com.squareup.okhttp3:okhttp:3.3.1' compile 'com.zhy:okhttputils:2.6.2' @@ -51,14 +55,13 @@ dependencies { compile 'de.hdodenhof:circleimageview:2.1.0' compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:v2.5.0' compile 'com.github.bumptech.glide:glide:3.7.0' - compile 'com.android.support:support-v4:25.0.0' + compile 'com.android.support:support-v4:25.0.1' compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar' compile 'com.jaeger.ninegridimageview:library:1.0.2' compile 'com.github.liuguangqiang.swipeback:library:1.0.2@aar' compile 'me.relex:circleindicator:1.2.1@aar' compile 'com.jakewharton:butterknife:8.4.0' compile 'net.grandcentrix.tray:tray:0.11.0' - compile 'com.annimon:stream:1.1.2' compile 'com.klinkerapps:sliding-activity:1.4.4' compile 'com.andkulikov:transitionseverywhere:1.6.9' compile 'com.github.jorgecastilloprz:fabprogresscircle:1.01@aar' @@ -68,6 +71,11 @@ dependencies { compile 'com.github.goka.flickableview:flickableview:1.0.0' compile 'net.hockeyapp.android:HockeySDK:4.1.1' compile 'me.himanshusoni.chatmessageview:chat-message-view:1.0.3' + compile 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT' testCompile 'junit:junit:4.12' annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' + compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" +} +repositories { + mavenCentral() } diff --git a/app/src/main/java/moe/tlaster/openween/App.java b/app/src/main/java/moe/tlaster/openween/App.java deleted file mode 100644 index 66db6ba..0000000 --- a/app/src/main/java/moe/tlaster/openween/App.java +++ /dev/null @@ -1,60 +0,0 @@ -package moe.tlaster.openween; - -import android.app.Application; -import android.app.job.JobInfo; -import android.app.job.JobScheduler; -import android.content.ComponentName; -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.widget.ImageView; - -import com.bumptech.glide.Glide; -import com.mikepenz.iconics.IconicsDrawable; -import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader; -import com.mikepenz.materialdrawer.util.DrawerImageLoader; -import com.mikepenz.materialdrawer.util.DrawerUIUtils; - -import moe.tlaster.openween.common.service.NotificationService; - -import static android.app.job.JobInfo.NETWORK_TYPE_ANY; - -/** - * Created by Tlaster on 2016/9/10. - */ -public class App extends Application { - - private static Context mContext; - - @Override - public void onCreate() { - super.onCreate(); - mContext = getApplicationContext(); - DrawerImageLoader.init(new AbstractDrawerImageLoader() { - @Override - public void set(ImageView imageView, Uri uri, Drawable placeholder) { - Glide.with(imageView.getContext()).load(uri).placeholder(placeholder).centerCrop().into(imageView); - } - @Override - public void cancel(ImageView imageView) { - Glide.clear(imageView); - } - - @Override - public Drawable placeholder(Context ctx, String tag) { - if (DrawerImageLoader.Tags.PROFILE.name().equals(tag)) { - return DrawerUIUtils.getPlaceHolder(ctx); - } else if (DrawerImageLoader.Tags.ACCOUNT_HEADER.name().equals(tag)) { - return new IconicsDrawable(ctx).iconText(" ").backgroundColorRes(com.mikepenz.materialdrawer.R.color.primary).sizeDp(56); - } else if ("customUrlItem".equals(tag)) { - return new IconicsDrawable(ctx).iconText(" ").backgroundColorRes(R.color.md_red_500).sizeDp(56); - } - return super.placeholder(ctx, tag); - } - }); - } - - public static Context getContext() { - return mContext; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/App.kt b/app/src/main/java/moe/tlaster/openween/App.kt new file mode 100644 index 0000000..ac2d4c5 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/App.kt @@ -0,0 +1,57 @@ +package moe.tlaster.openween + +import android.app.Application +import android.app.job.JobInfo +import android.app.job.JobScheduler +import android.content.ComponentName +import android.content.Context +import android.graphics.drawable.Drawable +import android.net.Uri +import android.widget.ImageView + +import com.bumptech.glide.Glide +import com.mikepenz.iconics.IconicsDrawable +import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader +import com.mikepenz.materialdrawer.util.DrawerImageLoader +import com.mikepenz.materialdrawer.util.DrawerUIUtils + +import moe.tlaster.openween.common.service.NotificationService + +import android.app.job.JobInfo.NETWORK_TYPE_ANY + +/** + * Created by Tlaster on 2016/9/10. + */ +class App : Application() { + + override fun onCreate() { + super.onCreate() + context = applicationContext + DrawerImageLoader.init(object : AbstractDrawerImageLoader() { + override fun set(imageView: ImageView?, uri: Uri?, placeholder: Drawable?) { + Glide.with(imageView!!.context).load(uri).placeholder(placeholder).centerCrop().into(imageView) + } + + override fun cancel(imageView: ImageView?) { + Glide.clear(imageView!!) + } + + override fun placeholder(ctx: Context, tag: String?): Drawable { + if (DrawerImageLoader.Tags.PROFILE.name == tag) { + return DrawerUIUtils.getPlaceHolder(ctx) + } else if (DrawerImageLoader.Tags.ACCOUNT_HEADER.name == tag) { + return IconicsDrawable(ctx).iconText(" ").backgroundColorRes(com.mikepenz.materialdrawer.R.color.primary).sizeDp(56) + } else if ("customUrlItem" == tag) { + return IconicsDrawable(ctx).iconText(" ").backgroundColorRes(R.color.md_red_500).sizeDp(56) + } + return super.placeholder(ctx, tag) + } + }) + } + + companion object { + + var context: Context? = null + private set + } +} diff --git a/app/src/main/java/moe/tlaster/openween/activity/AppCompatPreferenceActivity.java b/app/src/main/java/moe/tlaster/openween/activity/AppCompatPreferenceActivity.java deleted file mode 100644 index dc56cc1..0000000 --- a/app/src/main/java/moe/tlaster/openween/activity/AppCompatPreferenceActivity.java +++ /dev/null @@ -1,109 +0,0 @@ -package moe.tlaster.openween.activity; - -import android.content.res.Configuration; -import android.os.Bundle; -import android.preference.PreferenceActivity; -import android.support.annotation.LayoutRes; -import android.support.annotation.Nullable; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatDelegate; -import android.support.v7.widget.Toolbar; -import android.view.MenuInflater; -import android.view.View; -import android.view.ViewGroup; - -/** - * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls - * to be used with AppCompat. - */ -public abstract class AppCompatPreferenceActivity extends PreferenceActivity { - - private AppCompatDelegate mDelegate; - - @Override - protected void onCreate(Bundle savedInstanceState) { - getDelegate().installViewFactory(); - getDelegate().onCreate(savedInstanceState); - super.onCreate(savedInstanceState); - } - - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - getDelegate().onPostCreate(savedInstanceState); - } - - public ActionBar getSupportActionBar() { - return getDelegate().getSupportActionBar(); - } - - public void setSupportActionBar(@Nullable Toolbar toolbar) { - getDelegate().setSupportActionBar(toolbar); - } - - @Override - public MenuInflater getMenuInflater() { - return getDelegate().getMenuInflater(); - } - - @Override - public void setContentView(@LayoutRes int layoutResID) { - getDelegate().setContentView(layoutResID); - } - - @Override - public void setContentView(View view) { - getDelegate().setContentView(view); - } - - @Override - public void setContentView(View view, ViewGroup.LayoutParams params) { - getDelegate().setContentView(view, params); - } - - @Override - public void addContentView(View view, ViewGroup.LayoutParams params) { - getDelegate().addContentView(view, params); - } - - @Override - protected void onPostResume() { - super.onPostResume(); - getDelegate().onPostResume(); - } - - @Override - protected void onTitleChanged(CharSequence title, int color) { - super.onTitleChanged(title, color); - getDelegate().setTitle(title); - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - getDelegate().onConfigurationChanged(newConfig); - } - - @Override - protected void onStop() { - super.onStop(); - getDelegate().onStop(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - getDelegate().onDestroy(); - } - - public void invalidateOptionsMenu() { - getDelegate().invalidateOptionsMenu(); - } - - private AppCompatDelegate getDelegate() { - if (mDelegate == null) { - mDelegate = AppCompatDelegate.create(this, null); - } - return mDelegate; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/activity/AppCompatPreferenceActivity.kt b/app/src/main/java/moe/tlaster/openween/activity/AppCompatPreferenceActivity.kt new file mode 100644 index 0000000..ec74690 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/activity/AppCompatPreferenceActivity.kt @@ -0,0 +1,96 @@ +package moe.tlaster.openween.activity + +import android.content.res.Configuration +import android.os.Bundle +import android.preference.PreferenceActivity +import android.support.annotation.LayoutRes +import android.support.v7.app.ActionBar +import android.support.v7.app.AppCompatDelegate +import android.support.v7.widget.Toolbar +import android.view.MenuInflater +import android.view.View +import android.view.ViewGroup + +/** + * A [android.preference.PreferenceActivity] which implements and proxies the necessary calls + * to be used with AppCompat. + */ +abstract class AppCompatPreferenceActivity : PreferenceActivity() { + + private var mDelegate: AppCompatDelegate? = null + + override fun onCreate(savedInstanceState: Bundle?) { + delegate.installViewFactory() + delegate.onCreate(savedInstanceState) + super.onCreate(savedInstanceState) + } + + override fun onPostCreate(savedInstanceState: Bundle?) { + super.onPostCreate(savedInstanceState) + delegate.onPostCreate(savedInstanceState) + } + + val supportActionBar: ActionBar + get() = delegate.supportActionBar!! + + fun setSupportActionBar(toolbar: Toolbar?) { + delegate.setSupportActionBar(toolbar) + } + + override fun getMenuInflater(): MenuInflater { + return delegate.menuInflater + } + + override fun setContentView(@LayoutRes layoutResID: Int) { + delegate.setContentView(layoutResID) + } + + override fun setContentView(view: View) { + delegate.setContentView(view) + } + + override fun setContentView(view: View, params: ViewGroup.LayoutParams) { + delegate.setContentView(view, params) + } + + override fun addContentView(view: View, params: ViewGroup.LayoutParams) { + delegate.addContentView(view, params) + } + + override fun onPostResume() { + super.onPostResume() + delegate.onPostResume() + } + + override fun onTitleChanged(title: CharSequence, color: Int) { + super.onTitleChanged(title, color) + delegate.setTitle(title) + } + + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + delegate.onConfigurationChanged(newConfig) + } + + override fun onStop() { + super.onStop() + delegate.onStop() + } + + override fun onDestroy() { + super.onDestroy() + delegate.onDestroy() + } + + override fun invalidateOptionsMenu() { + delegate.invalidateOptionsMenu() + } + + private val delegate: AppCompatDelegate + get() { + if (mDelegate == null) { + mDelegate = AppCompatDelegate.create(this, null) + } + return mDelegate!! + } +} diff --git a/app/src/main/java/moe/tlaster/openween/activity/BaseActivity.java b/app/src/main/java/moe/tlaster/openween/activity/BaseActivity.java deleted file mode 100644 index cec6d97..0000000 --- a/app/src/main/java/moe/tlaster/openween/activity/BaseActivity.java +++ /dev/null @@ -1,144 +0,0 @@ -package moe.tlaster.openween.activity; - -import android.app.AlarmManager; -import android.app.PendingIntent; -import android.app.job.JobInfo; -import android.app.job.JobScheduler; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.os.Parcelable; -import android.preference.PreferenceManager; -import android.support.v7.app.AppCompatActivity; -import android.text.TextUtils; -import android.transition.Explode; -import android.transition.Slide; - -import net.hockeyapp.android.CrashManager; -import net.hockeyapp.android.UpdateManager; - -import java.lang.annotation.Annotation; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.lang.reflect.Field; -import java.util.Objects; - -import moe.tlaster.openween.R; -import moe.tlaster.openween.common.service.NotificationService; -import moe.tlaster.openween.core.api.Entity; - -import static android.app.job.JobInfo.NETWORK_TYPE_ANY; - -//import icepick.Icepick; - -/** - * Created by Asahi on 2016/10/2. - */ - -public abstract class BaseActivity extends AppCompatActivity { - private String mShouldRestart = "ShouldRestart"; - private int INTERVAL = 30 * 1000; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - //Icepick.restoreInstanceState(this, savedInstanceState); - if (savedInstanceState != null && savedInstanceState.getBoolean(mShouldRestart, false)) { - //It's better to restart the app than restore the state - goSplash(); - finish(); - return; - } - checkForUpdates(); - } - - protected void goSplash() { - Intent intent = new Intent(this, SplashActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - startActivity(intent); - finish(); - } - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - //Icepick.saveInstanceState(this, outState); - outState.putBoolean(mShouldRestart, true); - } - @Override - public void onDestroy() { - super.onDestroy(); - unregisterManagers(); - } - @Override - public void onResume() { - super.onResume(); - checkForCrashes(); - stopNotification(); - } - @Override - public void onPause() { - super.onPause(); - unregisterManagers(); - startNotification(); - } - private void checkForCrashes() { - CrashManager.register(this); - } - - private void unregisterManagers() { - UpdateManager.unregister(); - } - - private void checkForUpdates() { - UpdateManager.register(this); - } - - - public void startNotification() { - AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); - Intent intent = new Intent(this, NotificationService.class); - PendingIntent pendingIntent = PendingIntent.getService(this, 8975, intent, PendingIntent.FLAG_CANCEL_CURRENT); - alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, getInterval(), pendingIntent); - } - - private int getInterval() { - String[] choices = getResources().getStringArray(R.array.notification_interval_list); - String invertChoice = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.notification_interval_key), getString(R.string.notification_interval_default)); - int interval = 60 * 1000; - if (Objects.equals(invertChoice, choices[0])) { - interval = 60 * 1000; - } else if (Objects.equals(invertChoice, choices[1])) { - interval = 3 * 60 * 1000; - } else if (Objects.equals(invertChoice, choices[2])) { - interval = 5 * 60 * 1000; - } else if (Objects.equals(invertChoice, choices[3])) { - interval = 10 * 60 * 1000; - } else if (Objects.equals(invertChoice, choices[4])) { - interval = 30 * 60 * 1000; - } - return interval; - } - - public void stopNotification() { - AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); - Intent intent = new Intent(this, NotificationService.class); - PendingIntent pendingIntent = PendingIntent.getService(this, 8975, intent, PendingIntent.FLAG_CANCEL_CURRENT); - alarmManager.cancel(pendingIntent); - } - - /* - protected void startNotification() { - JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); - JobInfo.Builder builder = new JobInfo.Builder(8975, new ComponentName(getPackageName(), NotificationService.class.getName())) - .setPeriodic(getInterval()) - .setRequiredNetworkType(NETWORK_TYPE_ANY); - jobScheduler.schedule(builder.build()); - } - - protected void cancelAllJobs() { - ((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).cancel(8975); - } - */ -} diff --git a/app/src/main/java/moe/tlaster/openween/activity/BaseActivity.kt b/app/src/main/java/moe/tlaster/openween/activity/BaseActivity.kt new file mode 100644 index 0000000..c32fa97 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/activity/BaseActivity.kt @@ -0,0 +1,141 @@ +package moe.tlaster.openween.activity + +import android.app.AlarmManager +import android.app.PendingIntent +import android.app.job.JobInfo +import android.app.job.JobScheduler +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.os.Parcelable +import android.preference.PreferenceManager +import android.support.v7.app.AppCompatActivity +import android.text.TextUtils +import android.transition.Explode +import android.transition.Slide + +import net.hockeyapp.android.CrashManager +import net.hockeyapp.android.UpdateManager +import java.lang.annotation.Retention +import java.lang.annotation.RetentionPolicy +import java.lang.reflect.Field +import java.util.Objects + +import moe.tlaster.openween.R +import moe.tlaster.openween.common.service.NotificationService +import moe.tlaster.openween.core.api.Entity + +import android.app.job.JobInfo.NETWORK_TYPE_ANY + +//import icepick.Icepick; + +/** + * Created by Asahi on 2016/10/2. + */ + +abstract class BaseActivity : AppCompatActivity() { + private val mShouldRestart = "ShouldRestart" + private val INTERVAL = 30 * 1000 + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + //Icepick.restoreInstanceState(this, savedInstanceState); + if (savedInstanceState != null && savedInstanceState.getBoolean(mShouldRestart, false)) { + //It's better to restart the app than restore the state + goSplash() + finish() + return + } + checkForUpdates() + } + + protected fun goSplash() { + val intent = Intent(this, SplashActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + startActivity(intent) + finish() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + //Icepick.saveInstanceState(this, outState); + outState.putBoolean(mShouldRestart, true) + } + + public override fun onDestroy() { + super.onDestroy() + unregisterManagers() + } + + public override fun onResume() { + super.onResume() + checkForCrashes() + stopNotification() + } + + public override fun onPause() { + super.onPause() + unregisterManagers() + startNotification() + } + + private fun checkForCrashes() { + CrashManager.register(this) + } + + private fun unregisterManagers() { + UpdateManager.unregister() + } + + private fun checkForUpdates() { + UpdateManager.register(this) + } + + + fun startNotification() { + val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager + val intent = Intent(this, NotificationService::class.java) + val pendingIntent = PendingIntent.getService(this, 8975, intent, PendingIntent.FLAG_CANCEL_CURRENT) + alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, interval.toLong(), pendingIntent) + } + + private val interval: Int + get() { + val choices = resources.getStringArray(R.array.notification_interval_list) + val invertChoice = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.notification_interval_key), getString(R.string.notification_interval_default)) + var interval = 60 * 1000 + if (invertChoice == choices[0]) { + interval = 60 * 1000 + } else if (invertChoice == choices[1]) { + interval = 3 * 60 * 1000 + } else if (invertChoice == choices[2]) { + interval = 5 * 60 * 1000 + } else if (invertChoice == choices[3]) { + interval = 10 * 60 * 1000 + } else if (invertChoice == choices[4]) { + interval = 30 * 60 * 1000 + } + return interval + } + + fun stopNotification() { + val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager + val intent = Intent(this, NotificationService::class.java) + val pendingIntent = PendingIntent.getService(this, 8975, intent, PendingIntent.FLAG_CANCEL_CURRENT) + alarmManager.cancel(pendingIntent) + } + + /* + protected void startNotification() { + JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); + JobInfo.Builder builder = new JobInfo.Builder(8975, new ComponentName(getPackageName(), NotificationService.class.getName())) + .setPeriodic(getInterval()) + .setRequiredNetworkType(NETWORK_TYPE_ANY); + jobScheduler.schedule(builder.build()); + } + + protected void cancelAllJobs() { + ((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).cancel(8975); + } + */ +} diff --git a/app/src/main/java/moe/tlaster/openween/activity/DetailActivity.java b/app/src/main/java/moe/tlaster/openween/activity/DetailActivity.java deleted file mode 100644 index acd3b1e..0000000 --- a/app/src/main/java/moe/tlaster/openween/activity/DetailActivity.java +++ /dev/null @@ -1,104 +0,0 @@ -package moe.tlaster.openween.activity; - -import android.graphics.Color; -import android.support.design.widget.AppBarLayout; -import android.support.design.widget.TabLayout; -import android.support.v4.view.ViewPager; -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; -import android.support.v7.widget.Toolbar; -import android.view.Gravity; -import android.view.View; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.Toast; - -import com.transitionseverywhere.Fade; -import com.transitionseverywhere.Slide; -import com.transitionseverywhere.TransitionManager; - -import butterknife.BindView; -import butterknife.ButterKnife; -import moe.tlaster.openween.R; -import moe.tlaster.openween.common.controls.Pivot; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.common.helpers.WeiboCardHelper; -import moe.tlaster.openween.core.api.statuses.Query; -import moe.tlaster.openween.core.model.status.MessageModel; -import moe.tlaster.openween.fragment.detail.Comment; -import moe.tlaster.openween.fragment.detail.Repost; -import okhttp3.Call; - -public class DetailActivity extends BaseActivity { - @BindView(R.id.detail_appbar) - public AppBarLayout mAppBarLayout; - @BindView(R.id.detail_tab) - public TabLayout mTabLayout; - @BindView(R.id.detail_viewPager) - public ViewPager mViewPager; - @BindView(R.id.detail_weibo) - public View mWeibo; - @BindView(R.id.detail_progressBar) - public ProgressBar mProgressBar; - @BindView(R.id.detail_toolbar) - public Toolbar mToolbar; - private MessageModel mMessageModel; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_detail); - ButterKnife.bind(this); - setSupportActionBar(mToolbar); - mProgressBar.getIndeterminateDrawable().setColorFilter(Color.WHITE, android.graphics.PorterDuff.Mode.SRC_IN); - mMessageModel = getIntent().getExtras().getParcelable(getString(R.string.detail_message_model_name)); - Pivot.FragmentPageAdapter pageAdapter = new Pivot.FragmentPageAdapter(this, getSupportFragmentManager()); - pageAdapter.add(Repost.create(mMessageModel.getID())); - pageAdapter.add(Comment.create(mMessageModel.getID())); - mViewPager.setAdapter(pageAdapter); - mTabLayout.setupWithViewPager(mViewPager); - for (int i = 0; i < mTabLayout.getTabCount(); i++) { - TabLayout.Tab tab = mTabLayout.getTabAt(i); - tab.setCustomView(pageAdapter.getHeader(i)); - } - - mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { - @Override - public void onTabSelected(TabLayout.Tab tab) { - tab.getCustomView().setAlpha(1.f); - } - - @Override - public void onTabUnselected(TabLayout.Tab tab) { - tab.getCustomView().setAlpha(0.37f); - } - - @Override - public void onTabReselected(TabLayout.Tab tab) { } - }); - int index = mMessageModel.getText().toString().indexOf("\u5168\u6587\uff1a http://m.weibo.cn/"); - if (index != -1) { - Query.getStatus(mMessageModel.getID(), true, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - mProgressBar.setVisibility(View.GONE); - Toast.makeText(DetailActivity.this, "获取长微博失败", Toast.LENGTH_SHORT).show(); - } - - @Override - public void onResponse(MessageModel response, int id) { - mMessageModel = response; - response.setText(response.getLongText().getContent()); - WeiboCardHelper.setData(mWeibo, response, DetailActivity.this, true, Color.WHITE); - TransitionManager.beginDelayedTransition((LinearLayout) mProgressBar.getParent()); - mProgressBar.setVisibility(View.GONE); - mWeibo.setVisibility(View.VISIBLE); - } - }); - } else { - WeiboCardHelper.setData(mWeibo, mMessageModel, this, true, Color.WHITE); - mProgressBar.setVisibility(View.GONE); - mWeibo.setVisibility(View.VISIBLE); - } - } -} diff --git a/app/src/main/java/moe/tlaster/openween/activity/DetailActivity.kt b/app/src/main/java/moe/tlaster/openween/activity/DetailActivity.kt new file mode 100644 index 0000000..183d23f --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/activity/DetailActivity.kt @@ -0,0 +1,93 @@ +package moe.tlaster.openween.activity + +import android.graphics.Color +import android.support.design.widget.AppBarLayout +import android.support.design.widget.TabLayout +import android.support.v4.view.ViewPager +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.support.v7.widget.Toolbar +import android.view.Gravity +import android.view.View +import android.widget.LinearLayout +import android.widget.ProgressBar +import android.widget.Toast + +import com.transitionseverywhere.Fade +import com.transitionseverywhere.Slide +import com.transitionseverywhere.TransitionManager + +import butterknife.BindView +import butterknife.ButterKnife +import butterknife.bindView +import moe.tlaster.openween.R +import moe.tlaster.openween.common.controls.Pivot +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.common.helpers.WeiboCardHelper +import moe.tlaster.openween.core.api.statuses.Query +import moe.tlaster.openween.core.model.status.MessageModel +import moe.tlaster.openween.fragment.detail.Comment +import moe.tlaster.openween.fragment.detail.Repost +import okhttp3.Call + +class DetailActivity : BaseActivity() { + val mAppBarLayout: AppBarLayout by bindView(R.id.detail_appbar) + val mTabLayout: TabLayout by bindView(R.id.detail_tab) + val mViewPager: ViewPager by bindView(R.id.detail_viewPager) + val mWeibo: View by bindView(R.id.detail_weibo) + val mProgressBar: ProgressBar by bindView(R.id.detail_progressBar) + val mToolbar: Toolbar by bindView(R.id.detail_toolbar) + private var mMessageModel: MessageModel? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_detail) + setSupportActionBar(mToolbar) + mProgressBar.indeterminateDrawable.setColorFilter(Color.WHITE, android.graphics.PorterDuff.Mode.SRC_IN) + mMessageModel = intent.extras.getParcelable(getString(R.string.detail_message_model_name)) + val pageAdapter = Pivot.FragmentPageAdapter(this, supportFragmentManager) + pageAdapter.add(Repost.create(mMessageModel!!.id)) + pageAdapter.add(Comment.create(mMessageModel!!.id)) + mViewPager.adapter = pageAdapter + mTabLayout.setupWithViewPager(mViewPager) + for (i in 0..mTabLayout.tabCount - 1) { + val tab = mTabLayout.getTabAt(i) + tab!!.customView = pageAdapter.getHeader(i) + } + + mTabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { + override fun onTabSelected(tab: TabLayout.Tab) { + tab.customView!!.alpha = 1f + } + + override fun onTabUnselected(tab: TabLayout.Tab) { + tab.customView!!.alpha = 0.37f + } + + override fun onTabReselected(tab: TabLayout.Tab) { + } + }) + val index = mMessageModel!!.text.indexOf("\u5168\u6587\uff1a http://m.weibo.cn/") + if (index != -1) { + Query.getStatus(mMessageModel!!.id, true, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + mProgressBar.visibility = View.GONE + Toast.makeText(this@DetailActivity, "获取长微博失败", Toast.LENGTH_SHORT).show() + } + + override fun onResponse(response: MessageModel, id: Int) { + mMessageModel = response + response.text = response.longText!!.content!! + WeiboCardHelper.setData(mWeibo, response, this@DetailActivity, true, Color.WHITE) + TransitionManager.beginDelayedTransition(mProgressBar.parent as LinearLayout) + mProgressBar.visibility = View.GONE + mWeibo.visibility = View.VISIBLE + } + }) + } else { + WeiboCardHelper.setData(mWeibo, mMessageModel!!, this, true, Color.WHITE) + mProgressBar.visibility = View.GONE + mWeibo.visibility = View.VISIBLE + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/activity/DirectMessageActivity.java b/app/src/main/java/moe/tlaster/openween/activity/DirectMessageActivity.java deleted file mode 100644 index f2c0af6..0000000 --- a/app/src/main/java/moe/tlaster/openween/activity/DirectMessageActivity.java +++ /dev/null @@ -1,165 +0,0 @@ -package moe.tlaster.openween.activity; - -import android.graphics.Color; -import android.net.Uri; -import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; -import android.support.v7.widget.AppCompatEditText; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; -import android.text.TextUtils; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; -import android.widget.Toast; - -import com.annimon.stream.Collectors; -import com.annimon.stream.Stream; -import com.bumptech.glide.Glide; - -import java.util.ArrayList; -import java.util.List; -import java.util.Timer; -import java.util.TimerTask; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import de.hdodenhof.circleimageview.CircleImageView; -import moe.tlaster.openween.R; -import moe.tlaster.openween.adapter.DirectMessageAdapter; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.common.helpers.Reverse; -import moe.tlaster.openween.core.api.Entity; -import moe.tlaster.openween.core.api.directMessage.DirectMessage; -import moe.tlaster.openween.core.model.directmessage.DirectMessageListModel; -import moe.tlaster.openween.core.model.directmessage.DirectMessageModel; -import moe.tlaster.openween.core.model.user.UserModel; -import okhttp3.Call; - -public class DirectMessageActivity extends BaseActivity { - - @BindView(R.id.direct_message_user_header) - public View mUserHeader; - @BindView(R.id.direct_message_edit_text) - public AppCompatEditText mEditText; - @BindView(R.id.direct_message_list_layout) - public View mListLayout; - private UserModel mUser; - private Timer mTimer; - private RecyclerView mRecyclerView; - private SwipeRefreshLayout mRefresh; - private DirectMessageAdapter mAdapter; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_direct_message); - ButterKnife.bind(this); - mUser = getIntent().getExtras().getParcelable(getString(R.string.user_item_name)); - Glide.with(this).load(mUser.getAvatarLarge()).into((CircleImageView) mUserHeader.findViewById(R.id.user_img)); - ((TextView) mUserHeader.findViewById(R.id.user_name)).setText(mUser.getScreenName()); - ((TextView) mUserHeader.findViewById(R.id.user_name)).setTextColor(Color.WHITE); - ((TextView) mUserHeader.findViewById(R.id.user_sub_text)).setText(mUser.getDescription()); - ((TextView) mUserHeader.findViewById(R.id.user_sub_text)).setTextColor(Color.WHITE); - ((TextView) mUserHeader.findViewById(R.id.user_sub_text)).setLines(1); - mRecyclerView = (RecyclerView) mListLayout.findViewById(R.id.recyclerView); - mRefresh = (SwipeRefreshLayout) mListLayout.findViewById(R.id.refresher); - mRefresh.setOnRefreshListener(this::loadMore); - mRefresh.setEnabled(false); - mAdapter = new DirectMessageAdapter(); - mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); - mRecyclerView.setAdapter(mAdapter); - refresh(); - mTimer = new Timer(); - mTimer.scheduleAtFixedRate(new GetNewTask(), 30*1000, 30*1000); - } - - private void refresh() { - if (TextUtils.isEmpty(Entity.getAccessToken())) return; - DirectMessage.getConversation(String.valueOf(mUser.getID()), 20, 0, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - Toast.makeText(DirectMessageActivity.this, "加载失败", Toast.LENGTH_SHORT).show(); - } - - @Override - public void onResponse(DirectMessageListModel response, int id) { - mAdapter.setNewData(Stream.of(response.getDirectMessages()).custom(new Reverse<>()).collect(Collectors.toList())); - mRecyclerView.scrollToPosition(response.getDirectMessages().size() - 1); - mRefresh.setEnabled(true); - } - }); - } - - private void loadMore() { - long id = mAdapter.getData().get(0).getID(); - DirectMessage.getConversation(String.valueOf(mUser.getID()), 20, id, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - Toast.makeText(DirectMessageActivity.this, "加载失败", Toast.LENGTH_SHORT).show(); - mRefresh.setRefreshing(false); - } - - @Override - public void onResponse(DirectMessageListModel response, int id) { - List modelList = mAdapter.getData(); - response.getDirectMessages().remove(0); - for (DirectMessageModel directMessageModel : response.getDirectMessages()) { - modelList.add(0, directMessageModel); - } - mAdapter.setNewData(modelList); - mRecyclerView.scrollToPosition(response.getDirectMessages().size() - 1); - mRefresh.setRefreshing(false); - } - }); - } - - @Override - public void onDestroy() { - super.onDestroy(); - mTimer.cancel(); - } - - @OnClick(R.id.direct_message_send_button) - public void send() { - String text = mEditText.getText().toString(); - mEditText.setText(""); - DirectMessage.send(mUser.getID(), text, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - Toast.makeText(DirectMessageActivity.this, "发送失败", Toast.LENGTH_SHORT).show(); - } - - @Override - public void onResponse(DirectMessageModel response, int id) { - mAdapter.addData(new ArrayList(){{add(response);}}); - } - }); - } - - private void getNew() { - long id = mAdapter.getData().get(mAdapter.getData().size() - 1).getID(); - DirectMessage.getConversation(String.valueOf(mUser.getID()), id, 0, 20, 1, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - - @Override - public void onResponse(DirectMessageListModel response, int id) { - mAdapter.addData(response.getDirectMessages()); - mRecyclerView.scrollToPosition(mAdapter.getData().size()); - } - }); - } - - class GetNewTask extends TimerTask { - @Override - public void run() { - getNew(); - } - } -} diff --git a/app/src/main/java/moe/tlaster/openween/activity/DirectMessageActivity.kt b/app/src/main/java/moe/tlaster/openween/activity/DirectMessageActivity.kt new file mode 100644 index 0000000..0397ad1 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/activity/DirectMessageActivity.kt @@ -0,0 +1,150 @@ +package moe.tlaster.openween.activity + +import android.graphics.Color +import android.net.Uri +import android.support.v4.widget.SwipeRefreshLayout +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.support.v7.widget.AppCompatEditText +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.Toolbar +import android.text.TextUtils +import android.view.View +import android.widget.ImageView +import android.widget.TextView +import android.widget.Toast + +import com.bumptech.glide.Glide + +import java.util.ArrayList +import java.util.Timer +import java.util.TimerTask + +import butterknife.BindView +import butterknife.ButterKnife +import butterknife.OnClick +import butterknife.bindView +import de.hdodenhof.circleimageview.CircleImageView +import moe.tlaster.openween.R +import moe.tlaster.openween.adapter.DirectMessageAdapter +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.api.Entity +import moe.tlaster.openween.core.api.directMessage.DirectMessage +import moe.tlaster.openween.core.model.directmessage.DirectMessageListModel +import moe.tlaster.openween.core.model.directmessage.DirectMessageModel +import moe.tlaster.openween.core.model.user.UserModel +import okhttp3.Call + +class DirectMessageActivity : BaseActivity() { + val mUserHeader: View by bindView(R.id.direct_message_user_header) + val mEditText: AppCompatEditText by bindView(R.id.direct_message_edit_text) + val mListLayout: View by bindView(R.id.direct_message_list_layout) + private var mUser: UserModel? = null + private var mTimer: Timer? = null + private var mRecyclerView: RecyclerView? = null + private var mRefresh: SwipeRefreshLayout? = null + private var mAdapter: DirectMessageAdapter? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_direct_message) + mUser = intent.extras.getParcelable(getString(R.string.user_item_name)) + Glide.with(this).load(mUser!!.avatarLarge).into(mUserHeader.findViewById(R.id.user_img) as CircleImageView) + (mUserHeader.findViewById(R.id.user_name) as TextView).text = mUser!!.screenName + (mUserHeader.findViewById(R.id.user_name) as TextView).setTextColor(Color.WHITE) + (mUserHeader.findViewById(R.id.user_sub_text) as TextView).text = mUser!!.description + (mUserHeader.findViewById(R.id.user_sub_text) as TextView).setTextColor(Color.WHITE) + (mUserHeader.findViewById(R.id.user_sub_text) as TextView).setLines(1) + mRecyclerView = mListLayout.findViewById(R.id.recyclerView) as RecyclerView + mRefresh = mListLayout.findViewById(R.id.refresher) as SwipeRefreshLayout + mRefresh!!.setOnRefreshListener { this.loadMore() } + mRefresh!!.isEnabled = false + mAdapter = DirectMessageAdapter() + mRecyclerView!!.layoutManager = LinearLayoutManager(this) + mRecyclerView!!.adapter = mAdapter + refresh() + mTimer = Timer() + mTimer!!.scheduleAtFixedRate(GetNewTask(), (30 * 1000).toLong(), (30 * 1000).toLong()) + } + + private fun refresh() { + if (TextUtils.isEmpty(Entity.accessToken)) return + DirectMessage.getConversation(mUser!!.id.toString(), count = 20, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + Toast.makeText(this@DirectMessageActivity, "加载失败", Toast.LENGTH_SHORT).show() + } + + override fun onResponse(response: DirectMessageListModel, id: Int) { + mAdapter!!.setNewData(response.directMessages!!.reversed()) + mRecyclerView!!.scrollToPosition(response.directMessages!!.size - 1) + mRefresh!!.isEnabled = true + } + }) + } + + private fun loadMore() { + val id = mAdapter!!.data[0].id + DirectMessage.getConversation(mUser!!.id.toString(), count = 20, max_id = id, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + Toast.makeText(this@DirectMessageActivity, "加载失败", Toast.LENGTH_SHORT).show() + mRefresh!!.isRefreshing = false + } + + override fun onResponse(response: DirectMessageListModel, id: Int) { + val modelList = mAdapter!!.data + response.directMessages = response.directMessages!!.subList(1, response.directMessages!!.lastIndex) + for (directMessageModel in response.directMessages!!) { + modelList.add(0, directMessageModel) + } + mAdapter!!.setNewData(modelList) + mRecyclerView!!.scrollToPosition(response.directMessages!!.size - 1) + mRefresh!!.isRefreshing = false + } + }) + } + + override fun onDestroy() { + super.onDestroy() + mTimer!!.cancel() + } + + @OnClick(R.id.direct_message_send_button) + fun send() { + val text = mEditText.text.toString() + mEditText.setText("") + DirectMessage.send(mUser!!.id, text = text, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + Toast.makeText(this@DirectMessageActivity, "发送失败", Toast.LENGTH_SHORT).show() + } + + override fun onResponse(response: DirectMessageModel, id: Int) { + mAdapter!!.addData(object : ArrayList() { + init { + add(response) + } + }) + } + }) + } + + private fun getNew() { + val id = mAdapter!!.data[mAdapter!!.data.size - 1].id + DirectMessage.getConversation(mUser!!.id.toString(), max_id = id, count = 20, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + + } + + override fun onResponse(response: DirectMessageListModel, id: Int) { + mAdapter!!.addData(response.directMessages) + mRecyclerView!!.scrollToPosition(mAdapter!!.data.size) + } + }) + } + + internal inner class GetNewTask : TimerTask() { + override fun run() { + getNew() + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/activity/LoginActivity.java b/app/src/main/java/moe/tlaster/openween/activity/LoginActivity.java deleted file mode 100644 index dc0b156..0000000 --- a/app/src/main/java/moe/tlaster/openween/activity/LoginActivity.java +++ /dev/null @@ -1,169 +0,0 @@ -package moe.tlaster.openween.activity; - -import android.app.Dialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.AppCompatActivity; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.Base64; -import android.view.Menu; -import android.view.MenuItem; -import android.webkit.WebView; -import android.webkit.WebViewClient; -import android.widget.EditText; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.OnTextChanged; -import moe.tlaster.openween.R; -import moe.tlaster.openween.common.helpers.SettingHelper; - -/** - * Created by Asahi on 2016/9/26. - */ - -public class LoginActivity extends BaseActivity { - - @BindView(R.id.login_app_id) - public EditText mAppId; - @BindView(R.id.login_app_secret) - public EditText mAppSecret; - @BindView(R.id.login_redirect_uri) - public EditText mRedirectUri; - @BindView(R.id.login_scope) - public EditText mScope; - @BindView(R.id.login_package_name) - public EditText mPackageName; - - MenuItem mExitItem; - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_login); - ButterKnife.bind(this); - TextWatcher watcher = new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - - } - - @Override - public void afterTextChanged(Editable s) { - String str = s.toString().trim(); - if (isLoginData(str)) { - String[] data = decodeLoginData(s.toString()); - if (data == null || data.length < 5) return; - mAppId.setText(data[0].trim()); - mAppSecret.setText(data[1].trim()); - mRedirectUri.setText(data[2].trim()); - mScope.setText(data[3].trim()); - mPackageName.setText(data[4].trim()); - } - } - }; - mAppId.addTextChangedListener(watcher); - mAppSecret.addTextChangedListener(watcher); - mRedirectUri.addTextChangedListener(watcher); - mScope.addTextChangedListener(watcher); - mPackageName.addTextChangedListener(watcher); - } - - private static final String SEPERATOR = "::"; - private static final String START = "SS", END = "EE"; - private String[] decodeLoginData(String str) { - if (!isLoginData(str)) - return null; - String data = str.substring(START.length(), str.length() - END.length() - 1); - try { - return new String(Base64.decode(data, Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING | Base64.NO_CLOSE)).split(SEPERATOR); - } catch (Exception e) { - return null; - } - } - private boolean isLoginData(String str) { - return str.startsWith(START) && str.length() > START.length() + END.length() && str.endsWith(END); - } - - - @OnClick(R.id.login_next) - public void login(){ - Dialog dialog = new Dialog(this, R.style.AppTheme_NoActionBar); - dialog.setContentView(R.layout.login_web_view); - dialog.getWindow().setStatusBarColor(getWindow().getStatusBarColor()); - WebView webView = (WebView)dialog.findViewById(R.id.login_webview); - webView.getSettings().setJavaScriptEnabled(true); - webView.clearHistory(); - webView.clearCache(true); - webView.loadUrl("https://api.weibo.com/oauth2/authorize?client_id=" + mAppId.getText() + "&response_type=token&display=mobile&redirect_uri=" + - mRedirectUri.getText() + "&key_hash=" + mAppSecret.getText() + "&packagename=" + mPackageName.getText() + "&scope=" + mScope.getText()); - webView.setWebViewClient(new WebViewClient(){ - @Override - public void onPageFinished(WebView view, String url) { - super.onPageFinished(view, url); - if (!url.contains("error") && url.contains("access_token=")){ - int tokenIndex = url.indexOf("access_token="); - int expiresIndex = url.indexOf("expires_in="); - String token = url.substring(tokenIndex + 13, url.indexOf("&", tokenIndex)); - String expiresIn = url.substring(expiresIndex + 11, url.indexOf("&", expiresIndex)); - SettingHelper.setListSetting(LoginActivity.this, SettingHelper.ACCESSTOKEN, false, token); - goSplash(); - dialog.dismiss(); - } - } - }); - dialog.show(); - dialog.setTitle("登陆"); - dialog.setCancelable(true); - } - - @OnClick(R.id.login_what) - public void what(){ - ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("data", "SSMjExMTYwNjc5OjoxZTZlMzNkYjA4ZjkxOTIzMDZjNGFmYTBhNjFhZDU2Yzo6aHR0cDovL29hdXRoLndlaWNvLmNjOjplbWFpbCxkaXJlY3RfbWVzc2FnZXNfcmVhZCxkaXJlY3RfbWVzc2FnZXNfd3JpdGUsZnJpZW5kc2hpcHNfZ3JvdXBzX3JlYWQsZnJpZW5kc2hpcHNfZ3JvdXBzX3dyaXRlLHN0YXR1c2VzX3RvX21lX3JlYWQsZm9sbG93X2FwcF9vZmZpY2lhbF9taWNyb2Jsb2csaW52aXRhdGlvbl93cml0ZTo6Y29tLmVpY28ud2VpY286OkVFEE"); - clipboard.setPrimaryClip(clip); - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://gist.github.com/PeterCxy/3085799055f63c63c911")); - startActivity(browserIntent); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - menu.clear(); - - mExitItem = menu.add("取消"); - MenuItemCompat.setShowAsAction(mExitItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); - - return super.onCreateOptionsMenu(menu); - } - - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (mExitItem.equals(item)) { - cancel(); - return true; - } - return false; - } - - - public void cancel(){ - Intent homeIntent = new Intent(Intent.ACTION_MAIN); - homeIntent.addCategory( Intent.CATEGORY_HOME ); - homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(homeIntent); - } - -} diff --git a/app/src/main/java/moe/tlaster/openween/activity/LoginActivity.kt b/app/src/main/java/moe/tlaster/openween/activity/LoginActivity.kt new file mode 100644 index 0000000..a081bf6 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/activity/LoginActivity.kt @@ -0,0 +1,159 @@ +package moe.tlaster.openween.activity + +import android.app.Dialog +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Bundle +import android.support.v4.view.MenuItemCompat +import android.support.v7.app.AppCompatActivity +import android.text.Editable +import android.text.TextWatcher +import android.util.Base64 +import android.view.Menu +import android.view.MenuItem +import android.webkit.WebView +import android.webkit.WebViewClient +import android.widget.EditText +import butterknife.* + +import moe.tlaster.openween.R +import moe.tlaster.openween.common.helpers.SettingHelper + +/** + * Created by Asahi on 2016/9/26. + */ + +class LoginActivity : BaseActivity() { + val mAppId: EditText by bindView(R.id.login_app_id) + val mAppSecret: EditText by bindView(R.id.login_app_secret) + val mRedirectUri: EditText by bindView(R.id.login_redirect_uri) + val mScope: EditText by bindView(R.id.login_scope) + val mPackageName: EditText by bindView(R.id.login_package_name) + + internal var mExitItem: MenuItem? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_login) + val watcher = object : TextWatcher { + override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { + + } + + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { + + } + + override fun afterTextChanged(s: Editable) { + val str = s.toString().trim { it <= ' ' } + if (isLoginData(str)) { + val data = decodeLoginData(s.toString()) + if (data == null || data.size < 5) return + mAppId.setText(data[0].trim { it <= ' ' }) + mAppSecret.setText(data[1].trim { it <= ' ' }) + mRedirectUri.setText(data[2].trim { it <= ' ' }) + mScope.setText(data[3].trim { it <= ' ' }) + mPackageName.setText(data[4].trim { it <= ' ' }) + } + } + } + mAppId.addTextChangedListener(watcher) + mAppSecret.addTextChangedListener(watcher) + mRedirectUri.addTextChangedListener(watcher) + mScope.addTextChangedListener(watcher) + mPackageName.addTextChangedListener(watcher) + } + + private fun decodeLoginData(str: String): Array? { + if (!isLoginData(str)) + return null + val data = str.substring(START.length, str.length - END.length - 1) + try { + return String(Base64.decode(data, Base64.URL_SAFE or Base64.NO_WRAP or Base64.NO_PADDING or Base64.NO_CLOSE)).split(SEPERATOR.toRegex()).dropLastWhile(String::isEmpty).toTypedArray() + } catch (e: Exception) { + return null + } + + } + + private fun isLoginData(str: String): Boolean { + return str.startsWith(START) && str.length > START.length + END.length && str.endsWith(END) + } + + + @OnClick(R.id.login_next) + fun login() { + val dialog = Dialog(this, R.style.AppTheme_NoActionBar) + dialog.setContentView(R.layout.login_web_view) + dialog.window!!.statusBarColor = window.statusBarColor + val webView = dialog.findViewById(R.id.login_webview) as WebView + webView.settings.javaScriptEnabled = true + webView.clearHistory() + webView.clearCache(true) + webView.loadUrl("https://api.weibo.com/oauth2/authorize?client_id=" + mAppId.text + "&response_type=token&display=mobile&redirect_uri=" + + mRedirectUri.text + "&key_hash=" + mAppSecret.text + "&packagename=" + mPackageName.text + "&scope=" + mScope.text) + webView.setWebViewClient(object : WebViewClient() { + override fun onPageFinished(view: WebView, url: String) { + super.onPageFinished(view, url) + if (!url.contains("error") && url.contains("access_token=")) { + val tokenIndex = url.indexOf("access_token=") + val expiresIndex = url.indexOf("expires_in=") + val token = url.substring(tokenIndex + 13, url.indexOf("&", tokenIndex)) + val expiresIn = url.substring(expiresIndex + 11, url.indexOf("&", expiresIndex)) + SettingHelper.setListSetting(this@LoginActivity, SettingHelper.ACCESSTOKEN, false, token) + goSplash() + dialog.dismiss() + } + } + }) + dialog.show() + dialog.setTitle("登陆") + dialog.setCancelable(true) + } + + @OnClick(R.id.login_what) + fun what() { + val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clip = ClipData.newPlainText("data", "SSMjExMTYwNjc5OjoxZTZlMzNkYjA4ZjkxOTIzMDZjNGFmYTBhNjFhZDU2Yzo6aHR0cDovL29hdXRoLndlaWNvLmNjOjplbWFpbCxkaXJlY3RfbWVzc2FnZXNfcmVhZCxkaXJlY3RfbWVzc2FnZXNfd3JpdGUsZnJpZW5kc2hpcHNfZ3JvdXBzX3JlYWQsZnJpZW5kc2hpcHNfZ3JvdXBzX3dyaXRlLHN0YXR1c2VzX3RvX21lX3JlYWQsZm9sbG93X2FwcF9vZmZpY2lhbF9taWNyb2Jsb2csaW52aXRhdGlvbl93cml0ZTo6Y29tLmVpY28ud2VpY286OkVFEE") + clipboard.primaryClip = clip + val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://gist.github.com/PeterCxy/3085799055f63c63c911")) + startActivity(browserIntent) + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + menu.clear() + + mExitItem = menu.add("取消") + MenuItemCompat.setShowAsAction(mExitItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS) + + return super.onCreateOptionsMenu(menu) + } + + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (mExitItem == item) { + cancel() + return true + } + return false + } + + + fun cancel() { + val homeIntent = Intent(Intent.ACTION_MAIN) + homeIntent.addCategory(Intent.CATEGORY_HOME) + homeIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP + startActivity(homeIntent) + } + + companion object { + + private val SEPERATOR = "::" + private val START = "SS" + private val END = "EE" + } + +} diff --git a/app/src/main/java/moe/tlaster/openween/activity/MainActivity.java b/app/src/main/java/moe/tlaster/openween/activity/MainActivity.java deleted file mode 100644 index 46bc2f0..0000000 --- a/app/src/main/java/moe/tlaster/openween/activity/MainActivity.java +++ /dev/null @@ -1,124 +0,0 @@ -package moe.tlaster.openween.activity; - -import android.app.ActivityOptions; -import android.content.Intent; -import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; -import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.text.TextUtils; -import android.transition.Slide; -import android.view.Gravity; - -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.IconicsDrawable; -import com.mikepenz.materialdrawer.AccountHeaderBuilder; -import com.mikepenz.materialdrawer.Drawer; -import com.mikepenz.materialdrawer.DrawerBuilder; -import com.mikepenz.materialdrawer.holder.ImageHolder; -import com.mikepenz.materialdrawer.model.DividerDrawerItem; -import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; -import com.mikepenz.materialdrawer.model.ProfileDrawerItem; - -import butterknife.BindView; -import butterknife.ButterKnife; -import moe.tlaster.openween.R; -import moe.tlaster.openween.common.controls.Pivot; -import moe.tlaster.openween.common.entities.PostWeiboType; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.common.helpers.WeiboCardHelper; -import moe.tlaster.openween.core.api.friendships.Groups; -import moe.tlaster.openween.core.model.status.GroupListModel; -import moe.tlaster.openween.core.model.status.GroupModel; -import moe.tlaster.openween.core.model.user.UserModel; -import moe.tlaster.openween.fragment.main.DirectMessage; -import moe.tlaster.openween.fragment.main.Message; -import moe.tlaster.openween.fragment.main.Timeline; -import okhttp3.Call; - -public class MainActivity extends BaseActivity { - - @BindView(R.id.main_pivot) - public Pivot mPivot; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - if (!getIntent().hasExtra("user")) { - goSplash(); - return; - } - UserModel user = getIntent().getExtras().getParcelable("user"); - //setupWindowAnimations(); - ButterKnife.bind(this); - Timeline timeline = new Timeline(); - PrimaryDrawerItem drawerItemHome; - Drawer drawer = new DrawerBuilder() - .withActivity(this) - .addDrawerItems( - drawerItemHome = new PrimaryDrawerItem().withIdentifier(1).withName("首页").withIcon(GoogleMaterial.Icon.gmd_home).withOnDrawerItemClickListener((view, position, drawerItem) -> { - timeline.toGroup(-1); - return false; - }), - new DividerDrawerItem(), - new DividerDrawerItem(), - new PrimaryDrawerItem().withIdentifier(2).withName("设置").withIcon(GoogleMaterial.Icon.gmd_settings).withOnDrawerItemClickListener((view, position, drawerItem) -> { - startActivity(new Intent(MainActivity.this, SettingsActivity.class)); - return false; - }) - ) - .withCloseOnClick(true) - .build(); - drawer.setSelection(drawerItemHome, false); - Pivot.FragmentPageAdapter pageAdapter = new Pivot.FragmentPageAdapter(this, getSupportFragmentManager()); - pageAdapter.add(timeline); - pageAdapter.add(new Message()); - pageAdapter.add(new DirectMessage()); - mPivot.setAdapter(pageAdapter); - mPivot.setOffscreenPageLimit(3); - mPivot.setProfileImage(user.getAvatarLarge()); - mPivot.setProfileImageOnClickListener(view -> WeiboCardHelper.goUserActivity(user.getScreenName(), MainActivity.this)); - AccountHeaderBuilder accountHeaderBuilder = new AccountHeaderBuilder() - .withActivity(MainActivity.this) - .withDrawer(drawer) - .addProfiles(new ProfileDrawerItem().withNameShown(true).withName(user.getScreenName()).withEmail(user.getDescription()).withIcon(user.getAvatarLarge())) - .withOnAccountHeaderListener((view, profile, currentProfile) -> false); - if (!TextUtils.isEmpty(user.getCoverimage())) - accountHeaderBuilder.withHeaderBackground(new ImageHolder(user.getCoverimage())); - else - accountHeaderBuilder.withHeaderBackground(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); - accountHeaderBuilder.build(); - FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.main_fab); - fab.setImageDrawable(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_add).color(Color.WHITE).sizeDp(24)); - fab.setOnClickListener(view -> { - Intent i = new Intent(MainActivity.this, PostWeiboActivity.class); - i.putExtra(getString(R.string.post_weibo_type_name), PostWeiboType.NewPost); - startActivity(i, ActivityOptions.makeSceneTransitionAnimation(MainActivity.this).toBundle()); - }); - Groups.getGroups(new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - - @Override - public void onResponse(GroupListModel response, int id) { - for (int i = response.getLists().size() - 1; i >= 0; i--) { - GroupModel item = response.getLists().get(i); - drawer.addItemAtPosition(new PrimaryDrawerItem().withIdentifier(item.getID()).withName(item.getName()).withOnDrawerItemClickListener(((view, position, drawerItem) -> { - timeline.toGroup(item.getID()); - return false; - })), 3); - } - } - }); - } - - private void setupWindowAnimations() { - Slide slide = new Slide(); - slide.setDuration(500); - slide.setSlideEdge(Gravity.TOP); - getWindow().setEnterTransition(slide); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/activity/MainActivity.kt b/app/src/main/java/moe/tlaster/openween/activity/MainActivity.kt new file mode 100644 index 0000000..e936031 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/activity/MainActivity.kt @@ -0,0 +1,118 @@ +package moe.tlaster.openween.activity + +import android.app.ActivityOptions +import android.content.Intent +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import android.os.Bundle +import android.support.design.widget.FloatingActionButton +import android.text.TextUtils +import android.transition.Slide +import android.view.Gravity + +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.IconicsDrawable +import com.mikepenz.materialdrawer.AccountHeaderBuilder +import com.mikepenz.materialdrawer.Drawer +import com.mikepenz.materialdrawer.DrawerBuilder +import com.mikepenz.materialdrawer.holder.ImageHolder +import com.mikepenz.materialdrawer.model.DividerDrawerItem +import com.mikepenz.materialdrawer.model.PrimaryDrawerItem +import com.mikepenz.materialdrawer.model.ProfileDrawerItem + +import butterknife.BindView +import butterknife.ButterKnife +import butterknife.bindView +import moe.tlaster.openween.R +import moe.tlaster.openween.common.controls.Pivot +import moe.tlaster.openween.common.entities.PostWeiboType +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.common.helpers.WeiboCardHelper +import moe.tlaster.openween.core.api.friendships.Groups +import moe.tlaster.openween.core.model.status.GroupListModel +import moe.tlaster.openween.core.model.status.GroupModel +import moe.tlaster.openween.core.model.user.UserModel +import moe.tlaster.openween.fragment.main.DirectMessage +import moe.tlaster.openween.fragment.main.Message +import moe.tlaster.openween.fragment.main.Timeline +import okhttp3.Call + +class MainActivity : BaseActivity() { + val mPivot: Pivot by bindView(R.id.main_pivot) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + if (!intent.hasExtra("user")) { + goSplash() + return + } + val user = intent.extras.getParcelable("user") + //setupWindowAnimations(); + val timeline = Timeline() + val drawerItemHome: PrimaryDrawerItem =PrimaryDrawerItem().withIdentifier(1).withName("首页").withIcon(GoogleMaterial.Icon.gmd_home).withOnDrawerItemClickListener { view, position, drawerItem -> + timeline.toGroup(-1) + false + } + val drawer = DrawerBuilder() + .withActivity(this) + .addDrawerItems(drawerItemHome, + DividerDrawerItem(), + DividerDrawerItem(), + PrimaryDrawerItem().withIdentifier(2).withName("设置").withIcon(GoogleMaterial.Icon.gmd_settings).withOnDrawerItemClickListener { view, position, drawerItem -> + startActivity(Intent(this@MainActivity, SettingsActivity::class.java)) + false + } + ) + .withCloseOnClick(true) + .build() + drawer.setSelection(drawerItemHome, false) + val pageAdapter = Pivot.FragmentPageAdapter(this, supportFragmentManager) + pageAdapter.add(timeline) + pageAdapter.add(Message()) + pageAdapter.add(DirectMessage()) + mPivot!!.adapter = pageAdapter + mPivot!!.setOffscreenPageLimit(3) + mPivot!!.setProfileImage(user!!.avatarLarge!!) + mPivot!!.setProfileImageOnClickListener { view -> WeiboCardHelper.goUserActivity(user.screenName!!, this@MainActivity) } + val accountHeaderBuilder = AccountHeaderBuilder() + .withActivity(this@MainActivity) + .withDrawer(drawer) + .addProfiles(ProfileDrawerItem().withNameShown(true).withName(user.screenName).withEmail(user.description).withIcon(user.avatarLarge)) + .withOnAccountHeaderListener { view, profile, currentProfile -> false } + if (!TextUtils.isEmpty(user.coverimage)) + accountHeaderBuilder.withHeaderBackground(ImageHolder(user.coverimage)) + else + accountHeaderBuilder.withHeaderBackground(ColorDrawable(resources.getColor(R.color.colorPrimary))) + accountHeaderBuilder.build() + val fab = findViewById(R.id.main_fab) as FloatingActionButton + fab.setImageDrawable(IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_add).color(Color.WHITE).sizeDp(24)) + fab.setOnClickListener { view -> + val i = Intent(this@MainActivity, PostWeiboActivity::class.java) + i.putExtra(getString(R.string.post_weibo_type_name), PostWeiboType.NewPost) + startActivity(i, ActivityOptions.makeSceneTransitionAnimation(this@MainActivity).toBundle()) + } + Groups.getGroups(object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + + } + + override fun onResponse(response: GroupListModel, id: Int) { + for (i in response.lists!!.size - 1 downTo 0) { + val item = response.lists!![i] + drawer.addItemAtPosition(PrimaryDrawerItem().withIdentifier(item.id).withName(item.name).withOnDrawerItemClickListener { view, position, drawerItem -> + timeline.toGroup(item.id) + false + }, 3) + } + } + }) + } + + private fun setupWindowAnimations() { + val slide = Slide() + slide.duration = 500 + slide.slideEdge = Gravity.TOP + window.enterTransition = slide + } +} diff --git a/app/src/main/java/moe/tlaster/openween/activity/PostWeiboActivity.java b/app/src/main/java/moe/tlaster/openween/activity/PostWeiboActivity.java deleted file mode 100644 index ef1a961..0000000 --- a/app/src/main/java/moe/tlaster/openween/activity/PostWeiboActivity.java +++ /dev/null @@ -1,478 +0,0 @@ -package moe.tlaster.openween.activity; - -import android.Manifest; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Rect; -import android.support.annotation.NonNull; -import android.support.design.widget.TabLayout; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v4.view.PagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v7.widget.AppCompatTextView; -import android.os.Bundle; -import android.support.design.widget.CoordinatorLayout; -import android.support.design.widget.FloatingActionButton; -import android.support.design.widget.Snackbar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.AppCompatEditText; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; -import android.text.Editable; -import android.text.TextUtils; -import android.text.TextWatcher; -import android.transition.Slide; -import android.util.Log; -import android.util.SparseArray; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewTreeObserver; -import android.view.inputmethod.InputMethodManager; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.PopupWindow; -import android.widget.RelativeLayout; -import android.widget.Toast; - -import com.afollestad.materialdialogs.DialogAction; -import com.afollestad.materialdialogs.MaterialDialog; -import com.annimon.stream.Collectors; -import com.annimon.stream.Stream; -import com.bumptech.glide.Glide; -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; -import com.chad.library.adapter.base.listener.OnItemChildClickListener; -import com.goka.flickableview.FlickableImageView; -import com.mikepenz.fastadapter.FastAdapter; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.IconicsDrawable; -import com.mikepenz.iconics.view.IconicsCompatButton; - -import java.io.File; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.TreeMap; - -import butterknife.BindDimen; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import me.nereo.multi_image_selector.MultiImageSelector; -import me.nereo.multi_image_selector.MultiImageSelectorActivity; -import moe.tlaster.openween.R; -import moe.tlaster.openween.common.StaticResource; -import moe.tlaster.openween.common.controls.WeiboImageList; -import moe.tlaster.openween.common.entities.PostWeiboType; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.api.comments.Comments; -import moe.tlaster.openween.core.api.statuses.PostWeibo; -import moe.tlaster.openween.core.model.EmotionModel; -import moe.tlaster.openween.core.model.status.MessageModel; -import moe.tlaster.openween.core.model.status.PictureModel; -import moe.tlaster.openween.core.model.types.RepostType; -import okhttp3.Call; -import okhttp3.Response; - -public class PostWeiboActivity extends BaseActivity { - - private BaseQuickAdapter mAdapter; - private final int REQUEST_IMAGE = 0; - private final int REQUEST_READ_EXTERNAL_STORAGE = 1; - private MaterialDialog mDialog; - private int mMaxImageCount = 9; - private PostWeiboType mType; - @BindView(R.id.post_weibo_edit_text) - public AppCompatEditText mEditText; - @BindView(R.id.post_weibo_root) - public CoordinatorLayout mRoot; - @BindView(R.id.post_weibo_textcount) - public AppCompatTextView mTextCount; - @BindView(R.id.post_weibo_image_recycler) - public RecyclerView mImageRecycler; - @BindView(R.id.post_weibo_emotion_layout) - public LinearLayout mEmotionLayout; - @BindView(R.id.post_weibo_emotion_viewPager) - public ViewPager mEmotionViewPager; - @BindView(R.id.post_weibo_emotion_tab) - public TabLayout mEmotionTab; - @BindView(R.id.post_weibo_main_content) - public RelativeLayout mPostWeiboMain; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_post_weibo); - setupWindowAnimations(); - ButterKnife.bind(this); - mEditText.requestFocusFromTouch(); - mEditText.requestFocus(); - setEmotion(); - mAdapter = new BaseQuickAdapter(R.layout.weibo_image_list_itemtemplate, null) { - @Override - protected void convert(BaseViewHolder baseViewHolder, String path) { - FlickableImageView view = baseViewHolder.getView(R.id.weibo_image_list_item); - view.setMaxHeight(100); - view.setMaxWidth(100); - Glide.with(PostWeiboActivity.this).load(new File(path)).centerCrop().into(view); - baseViewHolder.addOnLongClickListener(R.id.weibo_image_list_item); - } - }; - mImageRecycler.setAdapter(mAdapter); - mImageRecycler.setLayoutManager(new GridLayoutManager(this, 9)); - mImageRecycler.addItemDecoration(new RecyclerView.ItemDecoration() { - @Override - public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { - int spacing = 20; - int spanCount = 9; - int position = parent.getChildAdapterPosition(view); - int column = position % spanCount; - outRect.left = spacing - column * spacing / spanCount; - outRect.right = (column + 1) * spacing / spanCount; - if (position < spanCount) { - outRect.top = spacing; - } - outRect.bottom = spacing; - } - }); - mImageRecycler.addOnItemTouchListener(new OnItemChildClickListener() { - @Override - public void SimpleOnItemChildClick(BaseQuickAdapter baseQuickAdapter, View view, int i) { - - } - - @Override - public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) { - switch (view.getId()){ - case R.id.weibo_image_list_item: - new MaterialDialog.Builder(PostWeiboActivity.this) - .title("注意") - .content("要删除图片吗") - .positiveText("是") - .negativeText("否") - .onPositive((dialog, which) -> mAdapter.remove(position)) - .show(); - break; - default: - break; - } - } - }); - mType = (PostWeiboType) getIntent().getSerializableExtra(getString(R.string.post_weibo_type_name)); - mEditText.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - - } - - @Override - public void afterTextChanged(Editable s) { - mTextCount.setText(String.valueOf(140 - getTextCount(s.toString()))); - } - }); - initData(); - } - - private int getTextCount(String value) { - try { - return (value.getBytes("GB2312").length + 1) / 2; - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - return -1; - } - } - - - private void setEmotion() { - if (StaticResource.getEmotions() != null && StaticResource.getEmotions().size() > 0) { - Map> map = Stream.of(StaticResource.getEmotions()).collect(Collectors.groupingBy(EmotionModel::getCategory, LinkedHashMap::new, Collectors.toList())); - mEmotionViewPager.setAdapter(new PagerAdapter() { - @Override - public int getCount() { - return map.keySet().size(); - } - @Override - public Object instantiateItem(ViewGroup container, int position) { - View itemTemplate = LayoutInflater.from(PostWeiboActivity.this).inflate(R.layout.list_layout, container, false); - itemTemplate.findViewById(R.id.refresher).setEnabled(false); - int column = 8; - RecyclerView recyclerView = (RecyclerView) itemTemplate.findViewById(R.id.recyclerView); - recyclerView.setLayoutManager(new GridLayoutManager(PostWeiboActivity.this, column)); - recyclerView.setAdapter(new BaseQuickAdapter(R.layout.emotion_image, map.get(map.keySet().toArray()[position])) { - @Override - protected void convert(BaseViewHolder baseViewHolder, EmotionModel emotionModel) { - baseViewHolder.setImageBitmap(R.id.emotion_img, BitmapFactory.decodeFile(emotionModel.getUrl())); - baseViewHolder.getView(R.id.emotion_img).setOnClickListener(view -> { - int position = mEditText.getSelectionStart(); - mEditText.setText(mEditText.getText().insert(position, emotionModel.getValue())); - mEditText.setSelection(position + emotionModel.getValue().length()); - }); - } - }); - container.addView(itemTemplate); - return itemTemplate; - } - @Override - public boolean isViewFromObject(View view, Object object) { - return view == object; - } - - @Override - public void destroyItem(ViewGroup container, int position, Object object) { - (container).removeView((View) object); - } - }); - mEmotionTab.setupWithViewPager(mEmotionViewPager); - for (int i = 0; i < mEmotionTab.getTabCount(); i++) { - TabLayout.Tab tab = mEmotionTab.getTabAt(i); - tab.setText(map.keySet().toArray()[i].toString()); - } - } - } - - - private void initData() { - if (mType == PostWeiboType.NewPost) return; - mMaxImageCount = 1; - if (!getIntent().hasExtra(getString(R.string.post_weibo_data_name))) return; - String data = getIntent().getStringExtra(getString(R.string.post_weibo_data_name)); - if (TextUtils.isEmpty(data)) return; - mEditText.setText(data); - if (mType == PostWeiboType.RePost) mEditText.setSelection(0); - else mEditText.setSelection(data.length()); - } - - private void setupWindowAnimations() { - Slide slide = new Slide(); - slide.setDuration(500); - slide.setSlideEdge(Gravity.BOTTOM); - getWindow().setEnterTransition(slide); - getWindow().setExitTransition(slide); - } - - @OnClick(R.id.post_weibo_add_emotion_button) - public void addEmotion(View view) { - InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(view.getWindowToken(), 0); - } - - private void requestPermission() { - ActivityCompat.requestPermissions(this ,new String[]{ Manifest.permission.READ_EXTERNAL_STORAGE , Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_READ_EXTERNAL_STORAGE); - } - - private void showImageSelector() { - MultiImageSelector.create() - .count(mMaxImageCount) - .origin(new ArrayList<>(mAdapter.getData())) - .start(this, REQUEST_IMAGE); - } - - @OnClick(R.id.post_weibo_add_image_button) - public void addImage() { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) - requestPermission(); - else - showImageSelector(); - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - switch (requestCode) { - case REQUEST_READ_EXTERNAL_STORAGE:{ - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showImageSelector(); - } else { - new MaterialDialog.Builder(PostWeiboActivity.this) - .title("注意") - .content("添加图片需要允许权限") - .positiveText("允许") - .negativeText("拒绝") - .onPositive((dialog, which) -> requestPermission()) - .show(); - } - } - break; - default: - break; - } - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode != REQUEST_IMAGE || resultCode != RESULT_OK) return; - mAdapter.setNewData(data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT)); - if (mAdapter.getData().size() > 0) mImageRecycler.setVisibility(View.VISIBLE); - else mImageRecycler.setVisibility(View.GONE); - } - - @OnClick(R.id.post_weibo_send_button) - public void send() { - if (TextUtils.isEmpty(mEditText.getText())) return; - if (getTextCount(mEditText.getText().toString()) < 0){ - new MaterialDialog.Builder(PostWeiboActivity.this) - .title("超出140字限制") - .content("是否删除多余字符?") - .positiveText("是") - .negativeText("否") - .onPositive((dialog, which) -> send()) - .show(); - return; - } - mDialog = new MaterialDialog.Builder(this) - .title("正在发送") - .content(getString(R.string.please_wait)) - .progress(true, 0) - .progressIndeterminateStyle(false) - .cancelable(false) - .canceledOnTouchOutside(false) - .show(); - switch (mType) { - case NewPost: newPost(); - break; - case RePost: rePost(); - break; - case Comment: comment(); - break; - case ReplyComment: replyComment(); - break; - default: - break; - } - } - private void replyComment() { - if (hasImage()) { - upload(mAdapter.getData(), new PostWeiboCallback>() { - @Override - void onResponse(Collection data) { - Comments.replyWithPic(getIntent().getExtras().getLong(getString(R.string.post_weibo_id_name)), getIntent().getExtras().getLong(getString(R.string.post_weibo_cid_name)), mEditText.getText().toString(), data.iterator().next().getPicID(), new PostWeiboJsonCallback<>()); - } - }); - } else { - Comments.reply(getIntent().getExtras().getLong(getString(R.string.post_weibo_id_name)), getIntent().getExtras().getLong(getString(R.string.post_weibo_cid_name)), mEditText.getText().toString(), new PostWeiboJsonCallback<>()); - } - } - - private void comment() { - if (hasImage()) { - upload(mAdapter.getData(), new PostWeiboCallback>() { - @Override - void onResponse(Collection data) { - Comments.postCommentWithPic(getIntent().getExtras().getLong(getString(R.string.post_weibo_id_name)), mEditText.getText().toString(), data.iterator().next().getPicID(), new PostWeiboJsonCallback<>()); - } - }); - } else { - Comments.postComment(getIntent().getExtras().getLong(getString(R.string.post_weibo_id_name)), mEditText.getText().toString(), new PostWeiboJsonCallback<>()); - } - } - - private void rePost() { - if (hasImage()) { - upload(mAdapter.getData(), new PostWeiboCallback>() { - @Override - void onResponse(Collection data) { - PostWeibo.repostWithPic(getIntent().getExtras().getLong(getString(R.string.post_weibo_id_name)), mEditText.getText().toString(), data.iterator().next().getPicID(), RepostType.None, new PostWeiboJsonCallback<>()); - } - }); - } else { - PostWeibo.repost(getIntent().getExtras().getLong(getString(R.string.post_weibo_id_name)), mEditText.getText().toString(), RepostType.None , new PostWeiboJsonCallback<>()); - } - } - - private void newPost() { - if (hasImage()) { - upload(mAdapter.getData(), new PostWeiboCallback>() { - @Override - void onResponse(Collection data) { - PostWeibo.postWithMultiPics(mEditText.getText().length() > 0 ? mEditText.getText().toString() : "分享图片", TextUtils.join(",", Stream.of(data).map(PictureModel::getPicID).toArray()), new PostWeiboJsonCallback<>()); - } - }); - } else if (mEditText.getText().length() > 0) { - PostWeibo.post(mEditText.getText().toString(), new PostWeiboJsonCallback<>()); - } - } - - private boolean hasImage() { - return mAdapter.getData().size() > 0; - } - - private void upload(List data, PostWeiboCallback> callback) { - JsonCallback jsonCallback = new JsonCallback() { - private Map mMap = new TreeMap<>(); - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(); - } - @Override - public void onResponse(PictureModel response, int id) { - mMap.put(id, response); - if (mMap.size() == data.size()) callback.onResponse(mMap.values()); - } - }; - for (int i = 0; i < data.size(); i++) { - int finalI = i; - PostWeibo.uploadPicture(new File(data.get(i)), new JsonCallback(){ - @Override - public void onError(Call call, Exception e, int id) { - jsonCallback.onError(call, e, id); - } - @Override - public void onResponse(PictureModel response, int id) { - jsonCallback.onResponse(response, finalI); - } - }); - } - } - - private void onError() { - onAction("发送失败"); - } - - private void onSuccess() { - onAction("发送成功"); - finish(); - } - - private void onAction(String content) { - mDialog.dismiss(); - Toast.makeText(this, content, Toast.LENGTH_SHORT).show(); - } - - private class PostWeiboJsonCallback extends JsonCallback { - @Override - public void onError(Call call, Exception e, int id) { - PostWeiboActivity.this.onError(); - } - - @Override - public void onResponse(T response, int id) { - PostWeiboActivity.this.onSuccess(); - } - } - - private abstract class PostWeiboCallback { - void onError(){ - PostWeiboActivity.this.onError(); - } - abstract void onResponse(T data); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/activity/PostWeiboActivity.kt b/app/src/main/java/moe/tlaster/openween/activity/PostWeiboActivity.kt new file mode 100644 index 0000000..90d2db7 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/activity/PostWeiboActivity.kt @@ -0,0 +1,441 @@ +package moe.tlaster.openween.activity + +import android.Manifest +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Rect +import android.support.design.widget.TabLayout +import android.support.v4.app.ActivityCompat +import android.support.v4.content.ContextCompat +import android.support.v4.view.PagerAdapter +import android.support.v4.view.ViewPager +import android.support.v7.widget.AppCompatTextView +import android.os.Bundle +import android.support.design.widget.CoordinatorLayout +import android.support.design.widget.FloatingActionButton +import android.support.design.widget.Snackbar +import android.support.v7.app.AppCompatActivity +import android.support.v7.widget.AppCompatEditText +import android.support.v7.widget.GridLayoutManager +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.Toolbar +import android.text.Editable +import android.text.TextUtils +import android.text.TextWatcher +import android.transition.Slide +import android.util.Log +import android.util.SparseArray +import android.view.Gravity +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.ViewTreeObserver +import android.view.inputmethod.InputMethodManager +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.RelativeLayout +import android.widget.Toast +import butterknife.* + +import com.afollestad.materialdialogs.DialogAction +import com.afollestad.materialdialogs.MaterialDialog +import com.bumptech.glide.Glide +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder +import com.chad.library.adapter.base.listener.OnItemChildClickListener +import com.goka.flickableview.FlickableImageView +import com.mikepenz.fastadapter.FastAdapter +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.IconicsDrawable +import com.mikepenz.iconics.view.IconicsCompatButton + +import java.io.File +import java.io.UnsupportedEncodingException +import java.util.ArrayList +import java.util.HashMap +import java.util.LinkedHashMap +import java.util.Objects +import java.util.TreeMap + +import me.nereo.multi_image_selector.MultiImageSelector +import me.nereo.multi_image_selector.MultiImageSelectorActivity +import moe.tlaster.openween.R +import moe.tlaster.openween.common.StaticResource +import moe.tlaster.openween.common.controls.WeiboImageList +import moe.tlaster.openween.common.entities.PostWeiboType +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.api.comments.Comments +import moe.tlaster.openween.core.api.statuses.PostWeibo +import moe.tlaster.openween.core.model.EmotionModel +import moe.tlaster.openween.core.model.comment.CommentModel +import moe.tlaster.openween.core.model.status.MessageModel +import moe.tlaster.openween.core.model.status.PictureModel +import moe.tlaster.openween.core.model.types.RepostType +import okhttp3.Call +import okhttp3.Response + +class PostWeiboActivity : BaseActivity() { + + private var mAdapter: BaseQuickAdapter? = null + private val REQUEST_IMAGE = 0 + private val REQUEST_READ_EXTERNAL_STORAGE = 1 + private var mDialog: MaterialDialog? = null + private var mMaxImageCount = 9 + private var mType: PostWeiboType? = null + val mEditText: AppCompatEditText by bindView(R.id.post_weibo_edit_text) + val mRoot: CoordinatorLayout by bindView(R.id.post_weibo_root) + val mTextCount: AppCompatTextView by bindView(R.id.post_weibo_textcount) + val mImageRecycler: RecyclerView by bindView(R.id.post_weibo_image_recycler) + val mEmotionLayout: LinearLayout by bindView(R.id.post_weibo_emotion_layout) + val mEmotionViewPager: ViewPager by bindView(R.id.post_weibo_emotion_viewPager) + val mEmotionTab: TabLayout by bindView(R.id.post_weibo_emotion_tab) + val mPostWeiboMain: RelativeLayout by bindView(R.id.post_weibo_main_content) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_post_weibo) + setupWindowAnimations() + mEditText.requestFocusFromTouch() + mEditText.requestFocus() + setEmotion() + mAdapter = object : BaseQuickAdapter(R.layout.weibo_image_list_itemtemplate, null) { + override fun convert(baseViewHolder: BaseViewHolder, path: String) { + val view = baseViewHolder.getView(R.id.weibo_image_list_item) + view.maxHeight = 100 + view.maxWidth = 100 + Glide.with(this@PostWeiboActivity).load(File(path)).centerCrop().into(view) + baseViewHolder.addOnLongClickListener(R.id.weibo_image_list_item) + } + } + mImageRecycler.adapter = mAdapter + mImageRecycler.layoutManager = GridLayoutManager(this, 9) + mImageRecycler.addItemDecoration(object : RecyclerView.ItemDecoration() { + override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) { + val spacing = 20 + val spanCount = 9 + val position = parent.getChildAdapterPosition(view) + val column = position % spanCount + outRect.left = spacing - column * spacing / spanCount + outRect.right = (column + 1) * spacing / spanCount + if (position < spanCount) { + outRect.top = spacing + } + outRect.bottom = spacing + } + }) + mImageRecycler.addOnItemTouchListener(object : OnItemChildClickListener() { + override fun SimpleOnItemChildClick(baseQuickAdapter: BaseQuickAdapter<*, *>, view: View, i: Int) { + + } + + override fun onItemChildLongClick(adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int) { + when (view!!.id) { + R.id.weibo_image_list_item -> MaterialDialog.Builder(this@PostWeiboActivity) + .title("注意") + .content("要删除图片吗") + .positiveText("是") + .negativeText("否") + .onPositive { dialog, which -> mAdapter!!.remove(position) } + .show() + else -> { + } + } + } + }) + mType = intent.getSerializableExtra(getString(R.string.post_weibo_type_name)) as PostWeiboType + mEditText.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { + + } + + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { + + } + + override fun afterTextChanged(s: Editable) { + mTextCount.text = (140 - getTextCount(s.toString())).toString() + } + }) + initData() + } + + private fun getTextCount(value: String): Int { + try { + return (value.toByteArray(charset("GB2312")).size + 1) / 2 + } catch (e: UnsupportedEncodingException) { + e.printStackTrace() + return -1 + } + + } + + + private fun setEmotion() { + if (StaticResource.emotions != null && StaticResource.emotions!!.isNotEmpty()) { + val map = StaticResource.emotions!!.groupBy { it.category } + mEmotionViewPager.adapter = object : PagerAdapter() { + override fun getCount(): Int { + return map.keys.size + } + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val itemTemplate = LayoutInflater.from(this@PostWeiboActivity).inflate(R.layout.list_layout, container, false) + itemTemplate.findViewById(R.id.refresher).isEnabled = false + val column = 8 + val recyclerView = itemTemplate.findViewById(R.id.recyclerView) as RecyclerView + recyclerView.layoutManager = GridLayoutManager(this@PostWeiboActivity, column) + recyclerView.adapter = object : BaseQuickAdapter(R.layout.emotion_image, map[map.keys.toTypedArray()[position]]) { + override fun convert(baseViewHolder: BaseViewHolder, emotionModel: EmotionModel) { + baseViewHolder.setImageBitmap(R.id.emotion_img, BitmapFactory.decodeFile(emotionModel.url)) + baseViewHolder.getView(R.id.emotion_img).setOnClickListener { view -> + val position = mEditText.selectionStart + mEditText.text = mEditText.text.insert(position, emotionModel.value) + mEditText.setSelection(position + emotionModel.value!!.length) + } + } + } + container.addView(itemTemplate) + return itemTemplate + } + + override fun isViewFromObject(view: View, `object`: Any): Boolean { + return view === `object` + } + + override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) { + container.removeView(`object` as View) + } + } + mEmotionTab.setupWithViewPager(mEmotionViewPager) + for (i in 0..mEmotionTab.tabCount - 1) { + val tab = mEmotionTab.getTabAt(i) + tab!!.text = map.keys.toTypedArray()[i] + } + } + } + + + private fun initData() { + if (mType == PostWeiboType.NewPost) return + mMaxImageCount = 1 + if (!intent.hasExtra(getString(R.string.post_weibo_data_name))) return + val data = intent.getStringExtra(getString(R.string.post_weibo_data_name)) + if (TextUtils.isEmpty(data)) return + mEditText.setText(data) + if (mType == PostWeiboType.RePost) + mEditText.setSelection(0) + else + mEditText.setSelection(data.length) + } + + private fun setupWindowAnimations() { + val slide = Slide() + slide.duration = 500 + slide.slideEdge = Gravity.BOTTOM + window.enterTransition = slide + window.exitTransition = slide + } + + @OnClick(R.id.post_weibo_add_emotion_button) + fun addEmotion(view: View) { + val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + imm.hideSoftInputFromWindow(view.windowToken, 0) + } + + private fun requestPermission() { + ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE), REQUEST_READ_EXTERNAL_STORAGE) + } + + private fun showImageSelector() { + MultiImageSelector.create() + .count(mMaxImageCount) + .origin(ArrayList(mAdapter!!.data)) + .start(this, REQUEST_IMAGE) + } + + @OnClick(R.id.post_weibo_add_image_button) + fun addImage() { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) + requestPermission() + else + showImageSelector() + } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + when (requestCode) { + REQUEST_READ_EXTERNAL_STORAGE -> { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + showImageSelector() + } else { + MaterialDialog.Builder(this@PostWeiboActivity) + .title("注意") + .content("添加图片需要允许权限") + .positiveText("允许") + .negativeText("拒绝") + .onPositive { dialog, which -> requestPermission() } + .show() + } + } + else -> { + } + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { + super.onActivityResult(requestCode, resultCode, data) + if (requestCode != REQUEST_IMAGE || resultCode != Activity.RESULT_OK) return + mAdapter!!.setNewData(data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT)) + if (mAdapter!!.data.size > 0) + mImageRecycler.visibility = View.VISIBLE + else + mImageRecycler.visibility = View.GONE + } + + @OnClick(R.id.post_weibo_send_button) + fun send() { + if (TextUtils.isEmpty(mEditText.text)) return + if (getTextCount(mEditText.text.toString()) < 0) { + MaterialDialog.Builder(this@PostWeiboActivity) + .title("超出140字限制") + .content("是否删除多余字符?") + .positiveText("是") + .negativeText("否") + .onPositive { dialog, which -> send() } + .show() + return + } + mDialog = MaterialDialog.Builder(this) + .title("正在发送") + .content(getString(R.string.please_wait)) + .progress(true, 0) + .progressIndeterminateStyle(false) + .cancelable(false) + .canceledOnTouchOutside(false) + .show() + when (mType) { + PostWeiboType.NewPost -> newPost() + PostWeiboType.RePost -> rePost() + PostWeiboType.Comment -> comment() + PostWeiboType.ReplyComment -> replyComment() + else -> { + } + } + } + + private fun replyComment() { + if (hasImage()) { + upload(mAdapter!!.data, object : PostWeiboCallback>() { + override fun onResponse(data: Collection) { + Comments.replyWithPic(intent.extras.getLong(getString(R.string.post_weibo_id_name)), intent.extras.getLong(getString(R.string.post_weibo_cid_name)), mEditText.text.toString(), pid = data.iterator().next().picID!!, callback = PostWeiboJsonCallback()) + } + }) + } else { + Comments.reply(intent.extras.getLong(getString(R.string.post_weibo_id_name)), intent.extras.getLong(getString(R.string.post_weibo_cid_name)), mEditText.text.toString(), callback = PostWeiboJsonCallback()) + } + } + + private fun comment() { + if (hasImage()) { + upload(mAdapter!!.data, object : PostWeiboCallback>() { + override fun onResponse(data: Collection) { + Comments.postCommentWithPic(intent.extras.getLong(getString(R.string.post_weibo_id_name)), mEditText.text.toString(), pid = data.iterator().next().picID!!, callback = PostWeiboJsonCallback()) + } + }) + } else { + Comments.postComment(intent.extras.getLong(getString(R.string.post_weibo_id_name)), mEditText.text.toString(), callback = PostWeiboJsonCallback()) + } + } + + private fun rePost() { + if (hasImage()) { + upload(mAdapter!!.data, object : PostWeiboCallback>() { + override fun onResponse(data: Collection) { + PostWeibo.repostWithPic(intent.extras.getLong(getString(R.string.post_weibo_id_name)), mEditText.text.toString(), pid = data.iterator().next().picID!!, callback = PostWeiboJsonCallback()) + } + }) + } else { + PostWeibo.repost(intent.extras.getLong(getString(R.string.post_weibo_id_name)), mEditText.text.toString(), RepostType.None, PostWeiboJsonCallback()) + } + } + + private fun newPost() { + if (hasImage()) { + upload(mAdapter!!.data, object : PostWeiboCallback>() { + override fun onResponse(data: Collection) { + PostWeibo.postWithMultiPics(if (mEditText.text.isNotEmpty()) mEditText.text.toString() else "分享图片", TextUtils.join(",", data.map { it.picID }), callback = PostWeiboJsonCallback()) + } + }) + } else if (mEditText.text.isNotEmpty()) { + PostWeibo.post(mEditText.text.toString(), callback = PostWeiboJsonCallback()) + } + } + + private fun hasImage(): Boolean { + return mAdapter!!.data.size > 0 + } + + private fun upload(data: List, callback: PostWeiboCallback>) { + val jsonCallback = object : JsonCallback() { + private val mMap = TreeMap() + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError() + } + + override fun onResponse(response: PictureModel, id: Int) { + mMap.put(id, response) + if (mMap.size == data.size) callback.onResponse(mMap.values) + } + } + for (i in data.indices) { + val finalI = i + PostWeibo.uploadPicture(File(data[i]), object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + jsonCallback.onError(call, e, id) + } + + override fun onResponse(response: PictureModel, id: Int) { + jsonCallback.onResponse(response, finalI) + } + }) + } + } + + private fun onError() { + onAction("发送失败") + } + + private fun onSuccess() { + onAction("发送成功") + finish() + } + + private fun onAction(content: String) { + mDialog!!.dismiss() + Toast.makeText(this, content, Toast.LENGTH_SHORT).show() + } + + private inner class PostWeiboJsonCallback : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + this@PostWeiboActivity.onError() + } + + override fun onResponse(response: T, id: Int) { + this@PostWeiboActivity.onSuccess() + } + } + + private abstract inner class PostWeiboCallback { + internal fun onError() { + this@PostWeiboActivity.onError() + } + + internal abstract fun onResponse(data: T) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/activity/SettingsActivity.java b/app/src/main/java/moe/tlaster/openween/activity/SettingsActivity.java deleted file mode 100644 index a454ddc..0000000 --- a/app/src/main/java/moe/tlaster/openween/activity/SettingsActivity.java +++ /dev/null @@ -1,314 +0,0 @@ -package moe.tlaster.openween.activity; - - -import android.annotation.TargetApi; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.res.Configuration; -import android.media.Ringtone; -import android.media.RingtoneManager; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.preference.CheckBoxPreference; -import android.preference.ListPreference; -import android.preference.Preference; -import android.preference.PreferenceActivity; -import android.preference.SwitchPreference; -import android.support.v7.app.ActionBar; -import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; -import android.preference.RingtonePreference; -import android.text.TextUtils; -import android.view.MenuItem; -import android.widget.Toast; - -import com.afollestad.materialdialogs.MaterialDialog; -import com.google.gson.Gson; -import com.zhy.http.okhttp.OkHttpUtils; -import com.zhy.http.okhttp.callback.Callback; -import com.zhy.http.okhttp.callback.FileCallBack; - -import net.hockeyapp.android.FeedbackManager; - -import moe.tlaster.openween.App; -import moe.tlaster.openween.R; -import moe.tlaster.openween.common.StaticResource; -import moe.tlaster.openween.common.helpers.DeviceHelper; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.api.statuses.Emotions; -import moe.tlaster.openween.core.model.EmotionModel; -import okhttp3.Call; -import okhttp3.Response; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.util.ArrayList; -import java.util.List; - -/** - * A {@link PreferenceActivity} that presents a set of application settings. On - * handset devices, settings are presented as a single list. On tablets, - * settings are split by category, with category headers shown to the left of - * the list of settings. - *

- * See - * Android Design: Settings for design guidelines and the Settings - * API Guide for more information on developing a Settings UI. - */ -public class SettingsActivity extends AppCompatPreferenceActivity { - /** - * A preference value change listener that updates the preference's summary - * to reflect its new value. - */ - private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = (preference, value) -> { - String stringValue = value.toString(); - - if (preference instanceof ListPreference) { - // For list preferences, look up the correct display value in - // the preference's 'entries' list. - ListPreference listPreference = (ListPreference) preference; - int index = listPreference.findIndexOfValue(stringValue); - - // Set the summary to reflect the new value. - preference.setSummary( - index >= 0 - ? listPreference.getEntries()[index] - : null); - - /*} else if (preference instanceof RingtonePreference) { - // For ringtone preferences, look up the correct display value - // using RingtoneManager. - if (TextUtils.isEmpty(stringValue)) { - // Empty values correspond to 'silent' (no ringtone). - preference.setSummary(R.string.pref_ringtone_silent); - - } else { - Ringtone ringtone = RingtoneManager.getRingtone( - preference.getContext(), Uri.parse(stringValue)); - - if (ringtone == null) { - // Clear the summary if there was a lookup error. - preference.setSummary(null); - } else { - // Set the summary to reflect the new ringtone display - // name. - String name = ringtone.getTitle(preference.getContext()); - preference.setSummary(name); - } - } - */ - } else { - // For all other preferences, set the summary to the value's - // simple string representation. - preference.setSummary(stringValue); - } - return true; - }; - - /** - * Helper method to determine if the device has an extra-large screen. For - * example, 10" tablets are extra-large. - */ - private static boolean isXLargeTablet(Context context) { - return (context.getResources().getConfiguration().screenLayout - & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE; - } - - /** - * Binds a preference's summary to its value. More specifically, when the - * preference's value is changed, its summary (line of text below the - * preference title) is updated to reflect the value. The summary is also - * immediately updated upon calling this method. The exact display format is - * dependent on the type of preference. - * - * @see #sBindPreferenceSummaryToValueListener - */ - private static void bindPreferenceSummaryToValue(Preference preference) { - // Set the listener to watch for value changes. - preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); - if (preference instanceof CheckBoxPreference || preference instanceof SwitchPreference) { - sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, - PreferenceManager - .getDefaultSharedPreferences(preference.getContext()) - .getBoolean(preference.getKey(), false)); - } else { - sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, - PreferenceManager - .getDefaultSharedPreferences(preference.getContext()) - .getString(preference.getKey(), "")); - } - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - //setupActionBar(); - } - - /** - * Set up the {@link android.app.ActionBar}, if the API is available. - */ - private void setupActionBar() { - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - // Show the Up button in the action bar. - actionBar.setDisplayHomeAsUpEnabled(true); - } - } - - /** - * {@inheritDoc} - */ - @Override - public boolean onIsMultiPane() { - return isXLargeTablet(this); - } - - /** - * {@inheritDoc} - */ - @Override - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public void onBuildHeaders(List

target) { - loadHeadersFromResource(R.xml.pref_headers, target); - } - - /** - * This method stops fragment injection in malicious applications. - * Make sure to deny any unknown fragments here. - */ - protected boolean isValidFragment(String fragmentName) { - return PreferenceFragment.class.getName().equals(fragmentName) - || GeneralPreferenceFragment.class.getName().equals(fragmentName) - || NotificationPreferenceFragment.class.getName().equals(fragmentName) - || BlockPreferenceFragment.class.getName().equals(fragmentName); - } - - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public static class BlockPreferenceFragment extends PreferenceFragment { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_block); - setHasOptionsMenu(false); - bindPreferenceSummaryToValue(findPreference(getString(R.string.block_text_key))); - bindPreferenceSummaryToValue(findPreference(getString(R.string.block_userid_key))); - } - } - - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public static class NotificationPreferenceFragment extends PreferenceFragment { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_notification); - setHasOptionsMenu(false); - bindPreferenceSummaryToValue(findPreference(getString(R.string.enable_notification_name))); - bindPreferenceSummaryToValue(findPreference(getString(R.string.notification_interval_key))); - bindPreferenceSummaryToValue(findPreference(getString(R.string.is_comment_notify_name))); - bindPreferenceSummaryToValue(findPreference(getString(R.string.is_mention_notify_name))); - bindPreferenceSummaryToValue(findPreference(getString(R.string.is_follower_notify_name))); - bindPreferenceSummaryToValue(findPreference(getString(R.string.is_message_notify_name))); - } - } - - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public static class GeneralPreferenceFragment extends PreferenceFragment { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_general); - setHasOptionsMenu(false); - bindPreferenceSummaryToValue(findPreference(getString(R.string.enable_animate_key))); - findPreference(getString(R.string.feedback_key)).setOnPreferenceClickListener(preference -> { - FeedbackManager.showFeedbackActivity(getActivity()); - return true; - }); - findPreference(getString(R.string.download_emotion_key)).setOnPreferenceClickListener(preference -> { - MaterialDialog[] dialog = {new MaterialDialog.Builder(getActivity()) - .title("正在下载表情") - .content(R.string.please_wait) - .progress(true, 0) - .cancelable(false) - .canceledOnTouchOutside(false) - .show()}; - Emotions.getEmotions(new JsonCallback>() { - @Override - public void onError(Call call, Exception e, int id) { - dialog[0].dismiss(); - Toast.makeText(App.getContext(), "下载表情失败", Toast.LENGTH_SHORT).show(); - } - - @Override - public void onResponse(List responseList, int id) { - dialog[0].hide(); - dialog[0] = new MaterialDialog.Builder(getActivity()) - .title("正在下载表情") - .content(R.string.please_wait) - .progress(false, responseList.size(), true) - .cancelable(false) - .canceledOnTouchOutside(false) - .show(); - for (int i = 0; i < responseList.size(); i++) { - EmotionModel item = responseList.get(i); - if (TextUtils.isEmpty(item.getCategory())) - item.setCategory("表情"); - String fileName = item.getValue().replace("[", "").replace("]", "") + ".jpg"; - String filePath = getActivity().getExternalFilesDir(null).getPath() + File.separator + "emotion" + File.separator + item.getCategory() + File.separator; - int finalI = i; - OkHttpUtils.get().url(item.getUrl()).build().execute(new FileCallBack(filePath, fileName) { - @Override - public void onError(Call call, Exception e, int id) { - - } - - @Override - public void onResponse(File response, int id) { - dialog[0].incrementProgress(1); - if (finalI == responseList.size() - 1) { - try { - File file = new File(getActivity().getExternalFilesDir(null).getPath() + File.separator + "emotion" + File.separator + "emotion.json"); - if (file.exists()) file.delete(); - file.createNewFile(); - OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file)); - outputStreamWriter.write(new Gson().toJson(responseList)); - outputStreamWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } - StaticResource.setEmotions(responseList); - dialog[0].dismiss(); - Toast.makeText(getActivity(), "下载表情完毕", Toast.LENGTH_SHORT).show(); - } - } - }); - item.setUrl(filePath + fileName); - responseList.set(i, item); - } - } - }); - return true; - }); - findPreference(getString(R.string.delete_emotion_key)).setOnPreferenceClickListener( preference -> { - File file = new File(getActivity().getExternalFilesDir(null), "emotion"); - if (file.exists()) { - MaterialDialog dialog = new MaterialDialog.Builder(getActivity()) - .title("正在删除表情") - .content(R.string.please_wait) - .progress(true, 0) - .show(); - DeviceHelper.deleteRecursive(file); - dialog.dismiss(); - Toast.makeText(getActivity(), "删除表情成功", Toast.LENGTH_SHORT).show(); - } - return true; - }); - } - } -} diff --git a/app/src/main/java/moe/tlaster/openween/activity/SettingsActivity.kt b/app/src/main/java/moe/tlaster/openween/activity/SettingsActivity.kt new file mode 100644 index 0000000..19163f0 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/activity/SettingsActivity.kt @@ -0,0 +1,304 @@ +package moe.tlaster.openween.activity + + +import android.annotation.TargetApi +import android.content.Context +import android.content.DialogInterface +import android.content.Intent +import android.content.res.Configuration +import android.media.Ringtone +import android.media.RingtoneManager +import android.net.Uri +import android.os.Build +import android.os.Bundle +import android.preference.CheckBoxPreference +import android.preference.ListPreference +import android.preference.Preference +import android.preference.PreferenceActivity +import android.preference.SwitchPreference +import android.support.v7.app.ActionBar +import android.preference.PreferenceFragment +import android.preference.PreferenceManager +import android.preference.RingtonePreference +import android.text.TextUtils +import android.view.MenuItem +import android.widget.Toast + +import com.afollestad.materialdialogs.MaterialDialog +import com.google.gson.Gson +import com.zhy.http.okhttp.OkHttpUtils +import com.zhy.http.okhttp.callback.Callback +import com.zhy.http.okhttp.callback.FileCallBack + +import net.hockeyapp.android.FeedbackManager + +import moe.tlaster.openween.App +import moe.tlaster.openween.R +import moe.tlaster.openween.common.StaticResource +import moe.tlaster.openween.common.helpers.DeviceHelper +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.api.statuses.Emotions +import moe.tlaster.openween.core.model.EmotionModel +import okhttp3.Call +import okhttp3.Response + +import java.io.File +import java.io.FileNotFoundException +import java.io.FileOutputStream +import java.io.IOException +import java.io.OutputStreamWriter +import java.util.ArrayList + +/** + * A [PreferenceActivity] that presents a set of application settings. On + * handset devices, settings are presented as a single list. On tablets, + * settings are split by category, with category headers shown to the left of + * the list of settings. + * + * + * See [ + * Android Design: Settings](http://developer.android.com/design/patterns/settings.html) for design guidelines and the [Settings + * API Guide](http://developer.android.com/guide/topics/ui/settings.html) for more information on developing a Settings UI. + */ +class SettingsActivity : AppCompatPreferenceActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + //setupActionBar(); + } + + /** + * Set up the [android.app.ActionBar], if the API is available. + */ + private fun setupActionBar() { + val actionBar = supportActionBar + actionBar?.setDisplayHomeAsUpEnabled(true) + } + + /** + * {@inheritDoc} + */ + override fun onIsMultiPane(): Boolean { + return isXLargeTablet(this) + } + + /** + * {@inheritDoc} + */ + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + override fun onBuildHeaders(target: List) { + loadHeadersFromResource(R.xml.pref_headers, target) + } + + /** + * This method stops fragment injection in malicious applications. + * Make sure to deny any unknown fragments here. + */ + override fun isValidFragment(fragmentName: String): Boolean { + return PreferenceFragment::class.java.name == fragmentName + || GeneralPreferenceFragment::class.java.name == fragmentName + || NotificationPreferenceFragment::class.java.name == fragmentName + || BlockPreferenceFragment::class.java.name == fragmentName + } + + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + class BlockPreferenceFragment : PreferenceFragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + addPreferencesFromResource(R.xml.pref_block) + setHasOptionsMenu(false) + bindPreferenceSummaryToValue(findPreference(getString(R.string.block_text_key))) + bindPreferenceSummaryToValue(findPreference(getString(R.string.block_userid_key))) + } + } + + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + class NotificationPreferenceFragment : PreferenceFragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + addPreferencesFromResource(R.xml.pref_notification) + setHasOptionsMenu(false) + bindPreferenceSummaryToValue(findPreference(getString(R.string.enable_notification_name))) + bindPreferenceSummaryToValue(findPreference(getString(R.string.notification_interval_key))) + bindPreferenceSummaryToValue(findPreference(getString(R.string.is_comment_notify_name))) + bindPreferenceSummaryToValue(findPreference(getString(R.string.is_mention_notify_name))) + bindPreferenceSummaryToValue(findPreference(getString(R.string.is_follower_notify_name))) + bindPreferenceSummaryToValue(findPreference(getString(R.string.is_message_notify_name))) + } + } + + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + class GeneralPreferenceFragment : PreferenceFragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + addPreferencesFromResource(R.xml.pref_general) + setHasOptionsMenu(false) + bindPreferenceSummaryToValue(findPreference(getString(R.string.enable_animate_key))) + findPreference(getString(R.string.feedback_key)).setOnPreferenceClickListener { preference -> + FeedbackManager.showFeedbackActivity(activity) + true + } + findPreference(getString(R.string.download_emotion_key)).setOnPreferenceClickListener { preference -> + val dialog = arrayOf(MaterialDialog.Builder(activity) + .title("正在下载表情") + .content(R.string.please_wait) + .progress(true, 0) + .cancelable(false) + .canceledOnTouchOutside(false) + .show()) + Emotions.getEmotions(object : JsonCallback>() { + override fun onError(call: Call, e: Exception, id: Int) { + dialog[0].dismiss() + Toast.makeText(App.context, "下载表情失败", Toast.LENGTH_SHORT).show() + } + + override fun onResponse(responseList: List, id: Int) { + dialog[0].hide() + dialog[0] = MaterialDialog.Builder(activity) + .title("正在下载表情") + .content(R.string.please_wait) + .progress(false, responseList.size, true) + .cancelable(false) + .canceledOnTouchOutside(false) + .show() + var result = responseList.toTypedArray() + for (i in result.indices) { + val item = result[i] + if (TextUtils.isEmpty(item.category)) + item.category = "表情" + val fileName = item.value!!.replace("[", "").replace("]", "") + ".jpg" + val filePath = activity.getExternalFilesDir(null)!!.path + File.separator + "emotion" + File.separator + item.category + File.separator + val finalI = i + OkHttpUtils.get().url(item.url).build().execute(object : FileCallBack(filePath, fileName) { + override fun onError(call: Call, e: Exception, id: Int) { + + } + + override fun onResponse(response: File, id: Int) { + dialog[0].incrementProgress(1) + if (finalI == result.size - 1) { + try { + val file = File(activity.getExternalFilesDir(null)!!.path + File.separator + "emotion" + File.separator + "emotion.json") + if (file.exists()) file.delete() + file.createNewFile() + val outputStreamWriter = OutputStreamWriter(FileOutputStream(file)) + outputStreamWriter.write(Gson().toJson(result)) + outputStreamWriter.close() + } catch (e: IOException) { + e.printStackTrace() + } + + StaticResource.emotions = result.toList() + dialog[0].dismiss() + Toast.makeText(activity, "下载表情完毕", Toast.LENGTH_SHORT).show() + } + } + }) + item.url = filePath + fileName + result[i] = item + } + } + }) + true + } + findPreference(getString(R.string.delete_emotion_key)).setOnPreferenceClickListener { preference -> + val file = File(activity.getExternalFilesDir(null), "emotion") + if (file.exists()) { + val dialog = MaterialDialog.Builder(activity) + .title("正在删除表情") + .content(R.string.please_wait) + .progress(true, 0) + .show() + DeviceHelper.deleteRecursive(file) + dialog.dismiss() + Toast.makeText(activity, "删除表情成功", Toast.LENGTH_SHORT).show() + } + true + } + } + } + + companion object { + /** + * A preference value change listener that updates the preference's summary + * to reflect its new value. + */ + private val sBindPreferenceSummaryToValueListener: Preference.OnPreferenceChangeListener = Preference.OnPreferenceChangeListener { preference, value -> + val stringValue = value.toString() + + if (preference is ListPreference) { + // For list preferences, look up the correct display value in + // the preference's 'entries' list. + val index = preference.findIndexOfValue(stringValue) + + // Set the summary to reflect the new value. + preference.setSummary( + if (index >= 0) + preference.entries[index] + else + null) + + /*} else if (preference instanceof RingtonePreference) { + // For ringtone preferences, look up the correct display value + // using RingtoneManager. + if (TextUtils.isEmpty(stringValue)) { + // Empty values correspond to 'silent' (no ringtone). + preference.setSummary(R.string.pref_ringtone_silent); + + } else { + Ringtone ringtone = RingtoneManager.getRingtone( + preference.getContext(), Uri.parse(stringValue)); + + if (ringtone == null) { + // Clear the summary if there was a lookup error. + preference.setSummary(null); + } else { + // Set the summary to reflect the new ringtone display + // name. + String name = ringtone.getTitle(preference.getContext()); + preference.setSummary(name); + } + } + */ + } else { + // For all other preferences, set the summary to the value's + // simple string representation. + preference.setSummary(stringValue) + } + true + } + + /** + * Helper method to determine if the device has an extra-large screen. For + * example, 10" tablets are extra-large. + */ + private fun isXLargeTablet(context: Context): Boolean { + return context.resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK >= Configuration.SCREENLAYOUT_SIZE_XLARGE + } + + /** + * Binds a preference's summary to its value. More specifically, when the + * preference's value is changed, its summary (line of text below the + * preference title) is updated to reflect the value. The summary is also + * immediately updated upon calling this method. The exact display format is + * dependent on the type of preference. + + * @see .sBindPreferenceSummaryToValueListener + */ + private fun bindPreferenceSummaryToValue(preference: Preference) { + // Set the listener to watch for value changes. + preference.onPreferenceChangeListener = sBindPreferenceSummaryToValueListener + if (preference is CheckBoxPreference || preference is SwitchPreference) { + sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, + PreferenceManager + .getDefaultSharedPreferences(preference.context) + .getBoolean(preference.key, false)) + } else { + sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, + PreferenceManager + .getDefaultSharedPreferences(preference.context) + .getString(preference.key, "")) + } + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/activity/SplashActivity.java b/app/src/main/java/moe/tlaster/openween/activity/SplashActivity.java deleted file mode 100644 index ea088d5..0000000 --- a/app/src/main/java/moe/tlaster/openween/activity/SplashActivity.java +++ /dev/null @@ -1,252 +0,0 @@ -package moe.tlaster.openween.activity; - -import android.app.ActivityOptions; -import android.app.job.JobInfo; -import android.app.job.JobScheduler; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.graphics.Bitmap; -import android.graphics.Color; -import android.graphics.PorterDuff; -import android.os.Build; -import android.os.Handler; -import android.os.Looper; -import android.preference.PreferenceManager; -import android.support.v4.app.ActivityOptionsCompat; -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.View; -import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.ProgressBar; - -import com.github.jorgecastilloprz.FABProgressCircle; -import com.github.jorgecastilloprz.listeners.FABProgressListener; -import com.google.gson.Gson; -import com.google.gson.JsonParser; -import com.mikepenz.materialdrawer.AccountHeaderBuilder; -import com.mikepenz.materialdrawer.model.ProfileDrawerItem; -import com.transitionseverywhere.AutoTransition; -import com.transitionseverywhere.ChangeBounds; -import com.transitionseverywhere.Transition; -import com.transitionseverywhere.TransitionManager; -import com.transitionseverywhere.TransitionSet; -import com.zhy.http.okhttp.OkHttpUtils; -import com.zhy.http.okhttp.callback.BitmapCallback; - -import net.hockeyapp.android.metrics.MetricsManager; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.Timer; -import java.util.TimerTask; - -import butterknife.BindView; -import butterknife.ButterKnife; -import de.hdodenhof.circleimageview.CircleImageView; -import moe.tlaster.openween.R; -import moe.tlaster.openween.common.StaticResource; -import moe.tlaster.openween.common.helpers.DeviceHelper; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.common.helpers.SettingHelper; -import moe.tlaster.openween.common.service.NotificationService; -import moe.tlaster.openween.core.api.Entity; -import moe.tlaster.openween.core.api.user.Account; -import moe.tlaster.openween.core.api.user.User; -import moe.tlaster.openween.core.model.EmotionModel; -import moe.tlaster.openween.core.model.LimitStatusModel; -import moe.tlaster.openween.core.model.user.UserModel; -import okhttp3.Call; - -import static android.app.job.JobInfo.NETWORK_TYPE_ANY; -import static com.transitionseverywhere.TransitionSet.ORDERING_TOGETHER; - -public class SplashActivity extends BaseActivity { - - @BindView(R.id.splash_progress) - public FABProgressCircle mFABProgressCircle; - @BindView(R.id.splash_icon) - public CircleImageView mCircleImageView; - private UserModel mUser; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - MetricsManager.register(getApplication()); - boolean enableAnimate = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.enable_animate_key), true); - if (enableAnimate) { - setContentView(R.layout.activity_splash); - ButterKnife.bind(this); - findViewById(R.id.splash_container).post(()->{ - TransitionManager.beginDelayedTransition((ViewGroup) SplashActivity.this.findViewById(R.id.splash_icon_container), new TransitionSet() - .setOrdering(ORDERING_TOGETHER) - //.addTransition(new Slide(Gravity.LEFT)) - .addTransition(new ChangeBounds()) - .setDuration(1000).setStartDelay(1000).addListener(new Transition.TransitionListenerAdapter() { - @Override - public void onTransitionEnd(Transition transition) { - allTransitionEnd(); - } - })); - findViewById(R.id.splash_title).setVisibility(View.VISIBLE); - }); - } else { - loadWithoutAnimate(); - } - } - - private void loadWithoutAnimate() { - if (SettingHelper.getListSetting(SplashActivity.this, SettingHelper.ACCESSTOKEN) == null) { - goLogin(); - } else { - try { - StaticResource.setEmotions(Arrays.asList(new Gson().fromJson(DeviceHelper.readFromFile(getExternalFilesDir(null).getPath() + File.separator + "emotion" + File.separator + "emotion.json"), EmotionModel[].class))); - } catch (NullPointerException e) { - } - Entity.setAccessToken(SettingHelper.getListSetting(this, SettingHelper.ACCESSTOKEN)[0]); - Account.getLimitStatus(new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - if (e.getMessage().contains("403")){ - List list = new LinkedList<>(Arrays.asList(SettingHelper.getListSetting(SplashActivity.this, SettingHelper.ACCESSTOKEN))); - list.remove(0); - SettingHelper.setListSetting(SplashActivity.this, SettingHelper.ACCESSTOKEN, true, list.toArray(new String[0])); - goLogin(); - } - } - @Override - public void onResponse(LimitStatusModel response, int id) { - Account.getUid(new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - goHome(); - } - @Override - public void onResponse(String response, int id) { - StaticResource.setUid(new JsonParser().parse(response).getAsJsonObject().get("uid").getAsLong()); - User.getUser(StaticResource.getUid(), new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - goHome(); - } - @Override - public void onResponse(UserModel response, int id) { - mUser = response; - Intent i = new Intent(SplashActivity.this, MainActivity.class); - i.putExtra("user", mUser); - startActivity(i); - finish(); - } - }); - } - }); - } - }); - } - } - - private void allTransitionEnd() { - mFABProgressCircle.show(); - if (SettingHelper.getListSetting(SplashActivity.this, SettingHelper.ACCESSTOKEN) == null) { - goLogin(); - } else { - try { - StaticResource.setEmotions(Arrays.asList(new Gson().fromJson(DeviceHelper.readFromFile(getExternalFilesDir(null).getPath() + File.separator + "emotion" + File.separator + "emotion.json"), EmotionModel[].class))); - } catch (NullPointerException e) { - } - Entity.setAccessToken(SettingHelper.getListSetting(this, SettingHelper.ACCESSTOKEN)[0]); - Account.getLimitStatus(new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - if (e.getMessage().contains("403")){ - List list = new LinkedList<>(Arrays.asList(SettingHelper.getListSetting(SplashActivity.this, SettingHelper.ACCESSTOKEN))); - list.remove(0); - SettingHelper.setListSetting(SplashActivity.this, SettingHelper.ACCESSTOKEN, true, list.toArray(new String[0])); - goLogin(); - } - } - @Override - public void onResponse(LimitStatusModel response, int id) { - Account.getUid(new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - goHome(); - } - @Override - public void onResponse(String response, int id) { - StaticResource.setUid(new JsonParser().parse(response).getAsJsonObject().get("uid").getAsLong()); - User.getUser(StaticResource.getUid(), new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - goHome(); - } - @Override - public void onResponse(UserModel response, int id) { - mUser = response; - OkHttpUtils.get().url(response.getAvatarLarge()).build().execute(new BitmapCallback() - { - FrameLayout root; - ImageView imgView; - - @Override - public void onError(Call call, Exception e, int id) { - goHome(); - } - @Override - public void onResponse(Bitmap response, int id) { - mFABProgressCircle.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { - imgView = (ImageView) v.findViewById(R.id.completeFabIcon); - root = (FrameLayout) v.findViewById(R.id.completeFabRoot); - if ((imgView != null) && (imgView.getScaleType() != ImageView.ScaleType.CENTER_INSIDE)) { - imgView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); - } - }); - mFABProgressCircle.attachListener(()-> new Handler(Looper.getMainLooper()).postDelayed(() -> { - mCircleImageView.setImageBitmap(response); - TransitionManager.beginDelayedTransition(root); - root.setVisibility(View.GONE); - navigate(); - }, 1000)); - mFABProgressCircle.beginFinalAnimation(); - } - }); - } - }); - } - }); - } - }); - } - } - - private void goLogin() { - Intent intent = new Intent(this, LoginActivity.class); - startActivity(intent); - finish(); - } - - private void goHome() { - Intent homeIntent = new Intent(Intent.ACTION_MAIN); - homeIntent.addCategory( Intent.CATEGORY_HOME ); - homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(homeIntent); - finish(); - } - - private void navigate() { - new Handler(Looper.getMainLooper()).postDelayed(() -> { - Intent i = new Intent(SplashActivity.this, MainActivity.class); - ActivityOptionsCompat transitionAnimation = ActivityOptionsCompat.makeSceneTransitionAnimation(SplashActivity.this, mCircleImageView, getString(R.string.user_profile_icon_name)); - i.putExtra("user", mUser); - startActivity(i, transitionAnimation.toBundle()); - finish(); - }, 2000); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/activity/SplashActivity.kt b/app/src/main/java/moe/tlaster/openween/activity/SplashActivity.kt new file mode 100644 index 0000000..7ed95ee --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/activity/SplashActivity.kt @@ -0,0 +1,242 @@ +package moe.tlaster.openween.activity + +import android.app.ActivityOptions +import android.app.job.JobInfo +import android.app.job.JobScheduler +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import android.graphics.Bitmap +import android.graphics.Color +import android.graphics.PorterDuff +import android.os.Build +import android.os.Handler +import android.os.Looper +import android.preference.PreferenceManager +import android.support.v4.app.ActivityOptionsCompat +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.text.TextUtils +import android.view.View +import android.view.ViewGroup +import android.widget.FrameLayout +import android.widget.ImageView +import android.widget.ProgressBar + +import com.github.jorgecastilloprz.FABProgressCircle +import com.github.jorgecastilloprz.listeners.FABProgressListener +import com.google.gson.Gson +import com.google.gson.JsonParser +import com.mikepenz.materialdrawer.AccountHeaderBuilder +import com.mikepenz.materialdrawer.model.ProfileDrawerItem +import com.transitionseverywhere.AutoTransition +import com.transitionseverywhere.ChangeBounds +import com.transitionseverywhere.Transition +import com.transitionseverywhere.TransitionManager +import com.transitionseverywhere.TransitionSet +import com.zhy.http.okhttp.OkHttpUtils +import com.zhy.http.okhttp.callback.BitmapCallback + +import net.hockeyapp.android.metrics.MetricsManager + +import java.io.File +import java.util.ArrayList +import java.util.Arrays +import java.util.LinkedList +import java.util.Timer +import java.util.TimerTask + +import butterknife.BindView +import butterknife.ButterKnife +import de.hdodenhof.circleimageview.CircleImageView +import moe.tlaster.openween.R +import moe.tlaster.openween.common.StaticResource +import moe.tlaster.openween.common.helpers.DeviceHelper +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.common.helpers.SettingHelper +import moe.tlaster.openween.common.service.NotificationService +import moe.tlaster.openween.core.api.Entity +import moe.tlaster.openween.core.api.user.Account +import moe.tlaster.openween.core.api.user.User +import moe.tlaster.openween.core.model.EmotionModel +import moe.tlaster.openween.core.model.LimitStatusModel +import moe.tlaster.openween.core.model.user.UserModel +import okhttp3.Call + +import android.app.job.JobInfo.NETWORK_TYPE_ANY +import butterknife.bindView +import com.transitionseverywhere.TransitionSet.ORDERING_TOGETHER + +class SplashActivity : BaseActivity() { + val mFABProgressCircle: FABProgressCircle by bindView(R.id.splash_progress) + val mCircleImageView: CircleImageView by bindView(R.id.splash_icon) + private var mUser: UserModel? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + MetricsManager.register(application) + val enableAnimate = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.enable_animate_key), true) + if (enableAnimate) { + setContentView(R.layout.activity_splash) + findViewById(R.id.splash_container).post { + TransitionManager.beginDelayedTransition(this@SplashActivity.findViewById(R.id.splash_icon_container) as ViewGroup, TransitionSet() + .setOrdering(ORDERING_TOGETHER) + //.addTransition(new Slide(Gravity.LEFT)) + .addTransition(ChangeBounds()) + .setDuration(1000).setStartDelay(1000).addListener(object : Transition.TransitionListenerAdapter() { + override fun onTransitionEnd(transition: Transition?) { + allTransitionEnd() + } + })) + findViewById(R.id.splash_title).visibility = View.VISIBLE + } + } else { + loadWithoutAnimate() + } + } + + private fun loadWithoutAnimate() { + if (SettingHelper.getListSetting(this@SplashActivity, SettingHelper.ACCESSTOKEN) == null) { + goLogin() + } else { + try { + StaticResource.emotions = Arrays.asList(*Gson().fromJson(DeviceHelper.readFromFile(getExternalFilesDir(null)!!.path + File.separator + "emotion" + File.separator + "emotion.json"), Array::class.java)) + } catch (e: NullPointerException) { + } + + Entity.accessToken = SettingHelper.getListSetting(this, SettingHelper.ACCESSTOKEN)!![0] + Account.getLimitStatus(object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + if (e.message!!.contains("403")) { + val list = LinkedList(Arrays.asList(*SettingHelper.getListSetting(this@SplashActivity, SettingHelper.ACCESSTOKEN)!!)) + list.removeAt(0) + SettingHelper.setListSetting(this@SplashActivity, SettingHelper.ACCESSTOKEN, true, *list.toTypedArray()) + goLogin() + } + } + + override fun onResponse(response: LimitStatusModel, id: Int) { + Account.getUid(object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + goHome() + } + + override fun onResponse(response: String, id: Int) { + StaticResource.uid = JsonParser().parse(response).asJsonObject.get("uid").asLong + User.getUser(StaticResource.uid, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + goHome() + } + + override fun onResponse(response: UserModel, id: Int) { + mUser = response + val i = Intent(this@SplashActivity, MainActivity::class.java) + i.putExtra("user", mUser) + startActivity(i) + finish() + } + }) + } + }) + } + }) + } + } + + private fun allTransitionEnd() { + mFABProgressCircle.show() + if (SettingHelper.getListSetting(this@SplashActivity, SettingHelper.ACCESSTOKEN) == null) { + goLogin() + } else { + try { + StaticResource.emotions = Arrays.asList(*Gson().fromJson(DeviceHelper.readFromFile(getExternalFilesDir(null)!!.path + File.separator + "emotion" + File.separator + "emotion.json"), Array::class.java)) + } catch (e: NullPointerException) { + } + + Entity.accessToken = SettingHelper.getListSetting(this, SettingHelper.ACCESSTOKEN)!![0] + Account.getLimitStatus(object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + if (e.message!!.contains("403")) { + val list = LinkedList(Arrays.asList(*SettingHelper.getListSetting(this@SplashActivity, SettingHelper.ACCESSTOKEN)!!)) + list.removeAt(0) + SettingHelper.setListSetting(this@SplashActivity, SettingHelper.ACCESSTOKEN, true, *list.toTypedArray()) + goLogin() + } + } + + override fun onResponse(response: LimitStatusModel, id: Int) { + Account.getUid(object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + goHome() + } + + override fun onResponse(response: String, id: Int) { + StaticResource.uid = JsonParser().parse(response).asJsonObject.get("uid").asLong + User.getUser(StaticResource.uid, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + goHome() + } + + override fun onResponse(response: UserModel, id: Int) { + mUser = response + OkHttpUtils.get().url(response.avatarLarge).build().execute(object : BitmapCallback() { + internal var root: FrameLayout? = null + internal var imgView: ImageView? = null + + override fun onError(call: Call, e: Exception, id: Int) { + goHome() + } + + override fun onResponse(response: Bitmap, id: Int) { + mFABProgressCircle.addOnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom -> + imgView = v.findViewById(R.id.completeFabIcon) as ImageView + root = v.findViewById(R.id.completeFabRoot) as FrameLayout + if (imgView != null && imgView!!.scaleType != ImageView.ScaleType.CENTER_INSIDE) { + imgView!!.scaleType = ImageView.ScaleType.CENTER_INSIDE + } + } + mFABProgressCircle.attachListener { + Handler(Looper.getMainLooper()).postDelayed({ + mCircleImageView.setImageBitmap(response) + TransitionManager.beginDelayedTransition(root) + root!!.visibility = View.GONE + navigate() + }, 1000) + } + mFABProgressCircle.beginFinalAnimation() + } + }) + } + }) + } + }) + } + }) + } + } + + private fun goLogin() { + val intent = Intent(this, LoginActivity::class.java) + startActivity(intent) + finish() + } + + private fun goHome() { + val homeIntent = Intent(Intent.ACTION_MAIN) + homeIntent.addCategory(Intent.CATEGORY_HOME) + homeIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP + startActivity(homeIntent) + finish() + } + + private fun navigate() { + Handler(Looper.getMainLooper()).postDelayed({ + val i = Intent(this@SplashActivity, MainActivity::class.java) + val transitionAnimation = ActivityOptionsCompat.makeSceneTransitionAnimation(this@SplashActivity, mCircleImageView, getString(R.string.user_profile_icon_name)) + i.putExtra("user", mUser) + startActivity(i, transitionAnimation.toBundle()) + finish() + }, 2000) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/activity/UserActivity.java b/app/src/main/java/moe/tlaster/openween/activity/UserActivity.java deleted file mode 100644 index 06f9733..0000000 --- a/app/src/main/java/moe/tlaster/openween/activity/UserActivity.java +++ /dev/null @@ -1,344 +0,0 @@ -package moe.tlaster.openween.activity; - -import android.app.Activity; -import android.app.ActivityOptions; -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.Color; -import android.net.Uri; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.text.TextUtils; -import android.view.Gravity; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.TextView; -import android.widget.Toast; - -import com.annimon.stream.Stream; -import com.bumptech.glide.Glide; -import com.github.jorgecastilloprz.FABProgressCircle; -import com.klinker.android.sliding.SlidingActivity; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.IconicsDrawable; -import com.transitionseverywhere.AutoTransition; -import com.transitionseverywhere.Slide; -import com.transitionseverywhere.TransitionManager; -import com.zhy.http.okhttp.OkHttpUtils; -import com.zhy.http.okhttp.callback.BitmapCallback; - -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import de.hdodenhof.circleimageview.CircleImageView; -import moe.tlaster.openween.R; -import moe.tlaster.openween.adapter.BaseModelAdapter; -import moe.tlaster.openween.common.SimpleDividerItemDecoration; -import moe.tlaster.openween.common.StaticResource; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.common.helpers.WeiboCardHelper; -import moe.tlaster.openween.core.api.blocks.Blocks; -import moe.tlaster.openween.core.api.friendships.Friends; -import moe.tlaster.openween.core.api.statuses.UserTimeline; -import moe.tlaster.openween.core.api.user.User; -import moe.tlaster.openween.core.model.status.MessageListModel; -import moe.tlaster.openween.core.model.status.MessageModel; -import moe.tlaster.openween.core.model.user.UserListModel; -import moe.tlaster.openween.core.model.user.UserModel; -import okhttp3.Call; - -/** - * Created by Asahi on 2016/10/10. - */ - -public class UserActivity extends SlidingActivity { - private UserModel mUser; - private CircleImageView mCircleImageView; - @BindView(R.id.user_stats_card) - public View mStatsCard; - @BindView(R.id.user_weibo_card) - public View mWeiboCard; - @BindView(R.id.user_progressbar) - public ProgressBar mProgressBar; - @BindView(R.id.user_information) - public LinearLayout mLinearLayout; - private Menu mMenu; - - @Override - public void init(Bundle savedInstanceState) { - setContent(R.layout.activity_user); - setPrimaryColors(getResources().getColor(R.color.colorPrimary), getResources().getColor(R.color.colorPrimaryDark)); - ButterKnife.bind(this); - mProgressBar.getIndeterminateDrawable().setColorFilter(Color.RED, android.graphics.PorterDuff.Mode.SRC_IN); - View headerView = getLayoutInflater().inflate(R.layout.user_icon, null); - mCircleImageView = (CircleImageView) headerView.findViewById(R.id.user_img); - mCircleImageView.setImageDrawable(new IconicsDrawable(this) - .icon(GoogleMaterial.Icon.gmd_person) - .color(Color.WHITE) - .sizeDp(24)); - setHeaderContent(headerView); - String userName = getIntent().getExtras().getString(getString(R.string.user_page_username_name)); - mWeiboCard.findViewById(R.id.user_weibo_all).setOnClickListener(this::goAllWeiboList); - mWeiboCard.findViewById(R.id.user_weibo_all_bottom).setOnClickListener(this::goAllWeiboList); - User.getUser(userName, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - Toast.makeText(UserActivity.this, "载入失败", Toast.LENGTH_SHORT).show(); - } - @Override - public void onResponse(UserModel response, int id) { - if (isDestroyed()) return; - if (response == null) { - Toast.makeText(UserActivity.this, "该用户不存在", Toast.LENGTH_SHORT).show(); - return; - } - mUser = response; - initMenu(); - initUser(); - initWeibo(); - mProgressBar.setVisibility(View.GONE); - } - }); - } - - private void initMenu() { - if (mUser.getID() == StaticResource.getUid()) { - mMenu.clear(); - return; - } - String blockUserid = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.block_userid_key), null); - if (TextUtils.isEmpty(blockUserid)) return; - if (Arrays.asList(blockUserid.split(",")).contains(String.valueOf(mUser.getID()))) { - mMenu.findItem(R.id.menu_user_block).setTitle("已屏蔽"); - } else { - mMenu.findItem(R.id.menu_user_block).setTitle("屏蔽"); - } - } - - private void goAllWeiboList(View view) { - Intent intent = new Intent(this, WeiboListActivity.class); - intent.putExtra(getString(R.string.weibo_list_user_id_name), mUser.getID()); - startActivity(intent); - } - - private void initWeibo() { - UserTimeline.getUserTimeline(mUser.getID(), 3, 1, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - - @Override - public void onResponse(MessageListModel response, int id) { - if (isDestroyed()) return; - if (response.getStatuses().size() > 0) { - WeiboCardHelper.setData(mWeiboCard.findViewById(R.id.user_weibo_1), response.getStatuses().get(0), UserActivity.this, true); - TransitionManager.beginDelayedTransition(mLinearLayout, new Slide(Gravity.BOTTOM)); - mWeiboCard.setVisibility(View.VISIBLE); - } else mWeiboCard.setVisibility(View.GONE); - if (response.getStatuses().size() > 1) - WeiboCardHelper.setData(mWeiboCard.findViewById(R.id.user_weibo_2), response.getStatuses().get(1), UserActivity.this, true); - else - mWeiboCard.findViewById(R.id.user_weibo_2).setVisibility(View.GONE); - if (response.getStatuses().size() > 2) - WeiboCardHelper.setData(mWeiboCard.findViewById(R.id.user_weibo_3), response.getStatuses().get(2), UserActivity.this, true); - else - mWeiboCard.findViewById(R.id.user_weibo_3).setVisibility(View.GONE); - } - }); - } - - private void initUser() { - setTitle(mUser.getScreenName()); - if (!TextUtils.isEmpty(mUser.getCoverimage())) - OkHttpUtils.get().url(mUser.getCoverimage()).build().execute(new BitmapCallback() - { - @Override - public void onError(Call call, Exception e, int id) { - - } - @Override - public void onResponse(Bitmap response, int id) { - if (!isDestroyed()) - setImage(response); - } - }); - OkHttpUtils.get().url(mUser.getAvatarLarge()).build().execute(new BitmapCallback() - { - @Override - public void onError(Call call, Exception e, int id) { - } - @Override - public void onResponse(Bitmap response, int id) { - if (isDestroyed()) return; - mCircleImageView.setImageBitmap(response); - } - }); - TransitionManager.beginDelayedTransition(mLinearLayout, new Slide(Gravity.BOTTOM)); - mStatsCard.setVisibility(View.VISIBLE); - mStatsCard.findViewById(R.id.user_stats_following_layout).setOnClickListener(view -> { - Intent intent = new Intent(this, UserListActivity.class); - intent.putExtra(getString(R.string.weibo_list_user_id_name), mUser.getID()); - intent.putExtra(getString(R.string.user_list_type_name), UserListActivity.USER_LIST_TYPE_FOLLOWING); - startActivity(intent); - }); - mStatsCard.findViewById(R.id.user_stats_follower_layout).setOnClickListener(view -> { - Intent intent = new Intent(this, UserListActivity.class); - intent.putExtra(getString(R.string.weibo_list_user_id_name), mUser.getID()); - intent.putExtra(getString(R.string.user_list_type_name), UserListActivity.USER_LIST_TYPE_FOLLOWER); - startActivity(intent); - }); - ((TextView) mStatsCard.findViewById(R.id.user_stats_user_des)).setText(mUser.getDescription()); - ((TextView) mStatsCard.findViewById(R.id.user_stats_follower_count)).setText(String.valueOf(mUser.getFollowersCount())); - ((TextView) mStatsCard.findViewById(R.id.user_stats_following_count)).setText(String.valueOf(mUser.getFriendsCount())); - if (!TextUtils.isEmpty(mUser.getUrl())) ((TextView) mStatsCard.findViewById(R.id.user_stats_url)).setText(mUser.getUrl()); - else mStatsCard.findViewById(R.id.user_stats_url_box).setVisibility(View.GONE); - if (!TextUtils.isEmpty(mUser.getLocation())) ((TextView) mStatsCard.findViewById(R.id.user_stats_location)).setText(mUser.getLocation()); - else mStatsCard.findViewById(R.id.user_stats_location_box).setVisibility(View.GONE); - if (!TextUtils.isEmpty(mUser.getVerifiedReason())) ((TextView) mStatsCard.findViewById(R.id.user_verified_reason)).setText(mUser.getVerifiedReason()); - else mStatsCard.findViewById(R.id.user_stats_verified_box).setVisibility(View.GONE); - ((TextView) mStatsCard.findViewById(R.id.user_stats_created_time)).setText(mUser.getCreatedAtDiffForHuman()); - checkForFollowState(); - mStatsCard.findViewById(R.id.user_stats_follow_state).setOnClickListener(view -> { - mProgressBar.setVisibility(View.VISIBLE); - mStatsCard.findViewById(R.id.user_stats_follow_state).setEnabled(false); - if (mUser.isFollowing()) { - Friends.unfollow(mUser.getID(), new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - Toast.makeText(UserActivity.this, "取消关注失败", Toast.LENGTH_SHORT).show(); - mProgressBar.setVisibility(View.GONE); - mStatsCard.findViewById(R.id.user_stats_follow_state).setEnabled(true); - } - - @Override - public void onResponse(UserModel response, int id) { - mUser.setFollowing(!mUser.isFollowing()); - checkForFollowState(); - mProgressBar.setVisibility(View.GONE); - mStatsCard.findViewById(R.id.user_stats_follow_state).setEnabled(true); - } - }); - } else { - Friends.follow(mUser.getID(), new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - Toast.makeText(UserActivity.this, "关注失败", Toast.LENGTH_SHORT).show(); - mProgressBar.setVisibility(View.GONE); - mStatsCard.findViewById(R.id.user_stats_follow_state).setEnabled(true); - } - - @Override - public void onResponse(UserModel response, int id) { - mUser.setFollowing(!mUser.isFollowing()); - checkForFollowState(); - mProgressBar.setVisibility(View.GONE); - mStatsCard.findViewById(R.id.user_stats_follow_state).setEnabled(true); - } - }); - } - }); - Friends.getFollowers(mUser.getID(), 3, 0, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - - @Override - public void onResponse(UserListModel response, int id) { - if (isDestroyed()) return; - if (response.getUsers().size() > 0) - Glide.with(UserActivity.this).load(response.getUsers().get(0).getAvatarLarge()).fitCenter().crossFade().into(((CircleImageView) mStatsCard.findViewById(R.id.user_stats_follower_icon_1))); - if (response.getUsers().size() > 1) - Glide.with(UserActivity.this).load(response.getUsers().get(1).getAvatarLarge()).fitCenter().crossFade().into(((CircleImageView) mStatsCard.findViewById(R.id.user_stats_follower_icon_2))); - if (response.getUsers().size() > 2) - Glide.with(UserActivity.this).load(response.getUsers().get(2).getAvatarLarge()).fitCenter().crossFade().into(((CircleImageView) mStatsCard.findViewById(R.id.user_stats_follower_icon_3))); - } - }); - Friends.getFriends(mUser.getID(), 3, 0, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - - @Override - public void onResponse(UserListModel response, int id) { - if (isDestroyed()) return; - if (response.getUsers().size() > 0) - Glide.with(UserActivity.this).load(response.getUsers().get(0).getAvatarLarge()).fitCenter().crossFade().into(((CircleImageView) mStatsCard.findViewById(R.id.user_stats_following_icon_1))); - if (response.getUsers().size() > 1) - Glide.with(UserActivity.this).load(response.getUsers().get(1).getAvatarLarge()).fitCenter().crossFade().into(((CircleImageView) mStatsCard.findViewById(R.id.user_stats_following_icon_2))); - if (response.getUsers().size() > 2) - Glide.with(UserActivity.this).load(response.getUsers().get(2).getAvatarLarge()).fitCenter().crossFade().into(((CircleImageView) mStatsCard.findViewById(R.id.user_stats_following_icon_3))); - } - }); - } - - private void checkForFollowState() { - if (mUser.isFollowing() && mUser.isFollowMe()) ((Button) mStatsCard.findViewById(R.id.user_stats_follow_state)).setText("互相关注"); - else if (mUser.isFollowMe()) ((Button) mStatsCard.findViewById(R.id.user_stats_follow_state)).setText("被关注"); - else if (mUser.isFollowing()) ((Button) mStatsCard.findViewById(R.id.user_stats_follow_state)).setText("正在关注"); - else if (mUser.getID() == StaticResource.getUid()) mStatsCard.findViewById(R.id.user_stats_follow_state).setVisibility(View.INVISIBLE); - else ((Button) mStatsCard.findViewById(R.id.user_stats_follow_state)).setText("关注"); - } - - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.activity_user, menu); - mMenu = menu; - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (mUser != null) { - switch (item.getItemId()) { - case R.id.menu_user_block: - String blockUserid = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.block_userid_key), null); - List blockList; - if (TextUtils.isEmpty(blockUserid)) blockList = new ArrayList<>(); - else blockList = new ArrayList<>(Arrays.asList(blockUserid.split(","))); - if (!blockList.contains(String.valueOf(mUser.getID()))) { - blockList.add(String.valueOf(mUser.getID())); - mMenu.findItem(R.id.menu_user_block).setTitle("已屏蔽"); - } else { - blockList.remove(String.valueOf(mUser.getID())); - mMenu.findItem(R.id.menu_user_block).setTitle("屏蔽"); - } - PreferenceManager.getDefaultSharedPreferences(this).edit().putString(getString(R.string.block_userid_key), TextUtils.join(",", blockList)).apply(); - break; - case R.id.menu_user_blacklist: - Blocks.addBlock(mUser.getID(), new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - - @Override - public void onResponse(UserModel response, int id) { - Toast.makeText(UserActivity.this, "丢进黑名单成功", Toast.LENGTH_SHORT).show(); - } - }); - break; - case R.id.menu_user_directmessage: - Intent intent = new Intent(this, DirectMessageActivity.class); - intent.putExtra(getString(R.string.user_item_name), mUser); - startActivity(intent); - break; - } - } - return super.onOptionsItemSelected(item); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/activity/UserActivity.kt b/app/src/main/java/moe/tlaster/openween/activity/UserActivity.kt new file mode 100644 index 0000000..e7b2acc --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/activity/UserActivity.kt @@ -0,0 +1,330 @@ +package moe.tlaster.openween.activity + +import android.app.Activity +import android.app.ActivityOptions +import android.content.Intent +import android.graphics.Bitmap +import android.graphics.Color +import android.net.Uri +import android.os.Bundle +import android.preference.PreferenceManager +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.text.TextUtils +import android.view.Gravity +import android.view.Menu +import android.view.MenuItem +import android.view.View +import android.widget.Button +import android.widget.LinearLayout +import android.widget.ProgressBar +import android.widget.TextView +import android.widget.Toast + +import com.bumptech.glide.Glide +import com.github.jorgecastilloprz.FABProgressCircle +import com.klinker.android.sliding.SlidingActivity +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.IconicsDrawable +import com.transitionseverywhere.AutoTransition +import com.transitionseverywhere.Slide +import com.transitionseverywhere.TransitionManager +import com.zhy.http.okhttp.OkHttpUtils +import com.zhy.http.okhttp.callback.BitmapCallback + +import java.net.URL +import java.util.ArrayList +import java.util.Arrays + +import butterknife.BindView +import butterknife.ButterKnife +import butterknife.OnClick +import butterknife.bindView +import de.hdodenhof.circleimageview.CircleImageView +import moe.tlaster.openween.R +import moe.tlaster.openween.adapter.BaseModelAdapter +import moe.tlaster.openween.common.SimpleDividerItemDecoration +import moe.tlaster.openween.common.StaticResource +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.common.helpers.WeiboCardHelper +import moe.tlaster.openween.core.api.blocks.Blocks +import moe.tlaster.openween.core.api.friendships.Friends +import moe.tlaster.openween.core.api.statuses.UserTimeline +import moe.tlaster.openween.core.api.user.User +import moe.tlaster.openween.core.model.status.MessageListModel +import moe.tlaster.openween.core.model.status.MessageModel +import moe.tlaster.openween.core.model.user.UserListModel +import moe.tlaster.openween.core.model.user.UserModel +import okhttp3.Call + +/** + * Created by Asahi on 2016/10/10. + */ + +class UserActivity : SlidingActivity() { + private var mUser: UserModel? = null + private var mCircleImageView: CircleImageView? = null + val mStatsCard: View by bindView(R.id.user_stats_card) + val mWeiboCard: View by bindView(R.id.user_weibo_card) + val mProgressBar: ProgressBar by bindView(R.id.user_progressbar) + val mLinearLayout: LinearLayout by bindView(R.id.user_information) + private var mMenu: Menu? = null + + override fun init(savedInstanceState: Bundle?) { + setContent(R.layout.activity_user) + setPrimaryColors(resources.getColor(R.color.colorPrimary), resources.getColor(R.color.colorPrimaryDark)) + mProgressBar.indeterminateDrawable.setColorFilter(Color.RED, android.graphics.PorterDuff.Mode.SRC_IN) + val headerView = layoutInflater.inflate(R.layout.user_icon, null) + mCircleImageView = headerView.findViewById(R.id.user_img) as CircleImageView + mCircleImageView!!.setImageDrawable(IconicsDrawable(this) + .icon(GoogleMaterial.Icon.gmd_person) + .color(Color.WHITE) + .sizeDp(24)) + setHeaderContent(headerView) + val userName = intent.extras.getString(getString(R.string.user_page_username_name)) + mWeiboCard.findViewById(R.id.user_weibo_all).setOnClickListener { this.goAllWeiboList(it) } + mWeiboCard.findViewById(R.id.user_weibo_all_bottom).setOnClickListener{ this.goAllWeiboList(it) } + User.getUser(userName, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + Toast.makeText(this@UserActivity, "载入失败", Toast.LENGTH_SHORT).show() + } + + override fun onResponse(response: UserModel?, id: Int) { + if (isDestroyed) return + if (response == null) { + Toast.makeText(this@UserActivity, "该用户不存在", Toast.LENGTH_SHORT).show() + return + } + mUser = response + initMenu() + initUser() + initWeibo() + mProgressBar.visibility = View.GONE + } + }) + } + + private fun initMenu() { + if (mUser!!.id === StaticResource.uid) { + mMenu!!.clear() + return + } + val blockUserid = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.block_userid_key), null) + if (TextUtils.isEmpty(blockUserid)) return + if (Arrays.asList(*blockUserid!!.split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()).contains(mUser!!.id.toString())) { + mMenu!!.findItem(R.id.menu_user_block).title = "已屏蔽" + } else { + mMenu!!.findItem(R.id.menu_user_block).title = "屏蔽" + } + } + + private fun goAllWeiboList(view: View) { + val intent = Intent(this, WeiboListActivity::class.java) + intent.putExtra(getString(R.string.weibo_list_user_id_name), mUser!!.id) + startActivity(intent) + } + + private fun initWeibo() { + UserTimeline.getUserTimeline(mUser!!.id, count = 3, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + + } + + override fun onResponse(response: MessageListModel, id: Int) { + if (isDestroyed) return + if (response.statuses!!.isNotEmpty()) { + WeiboCardHelper.setData(mWeiboCard.findViewById(R.id.user_weibo_1), response.statuses!![0], this@UserActivity, true) + TransitionManager.beginDelayedTransition(mLinearLayout, Slide(Gravity.BOTTOM)) + mWeiboCard.visibility = View.VISIBLE + } else + mWeiboCard.visibility = View.GONE + if (response.statuses!!.size > 1) + WeiboCardHelper.setData(mWeiboCard.findViewById(R.id.user_weibo_2), response.statuses!![1], this@UserActivity, true) + else + mWeiboCard.findViewById(R.id.user_weibo_2).visibility = View.GONE + if (response.statuses!!.size > 2) + WeiboCardHelper.setData(mWeiboCard.findViewById(R.id.user_weibo_3), response.statuses!![2], this@UserActivity, true) + else + mWeiboCard.findViewById(R.id.user_weibo_3).visibility = View.GONE + } + }) + } + + private fun initUser() { + title = mUser!!.screenName!! + if (!TextUtils.isEmpty(mUser!!.coverimage)) + OkHttpUtils.get().url(mUser!!.coverimage).build().execute(object : BitmapCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + + } + + override fun onResponse(response: Bitmap, id: Int) { + if (!isDestroyed) + setImage(response) + } + }) + OkHttpUtils.get().url(mUser!!.avatarLarge).build().execute(object : BitmapCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + } + + override fun onResponse(response: Bitmap, id: Int) { + if (isDestroyed) return + mCircleImageView!!.setImageBitmap(response) + } + }) + TransitionManager.beginDelayedTransition(mLinearLayout, Slide(Gravity.BOTTOM)) + mStatsCard.visibility = View.VISIBLE + mStatsCard.findViewById(R.id.user_stats_following_layout).setOnClickListener { view -> + val intent = Intent(this, UserListActivity::class.java) + intent.putExtra(getString(R.string.weibo_list_user_id_name), mUser!!.id) + intent.putExtra(getString(R.string.user_list_type_name), UserListActivity.USER_LIST_TYPE_FOLLOWING) + startActivity(intent) + } + mStatsCard.findViewById(R.id.user_stats_follower_layout).setOnClickListener { view -> + val intent = Intent(this, UserListActivity::class.java) + intent.putExtra(getString(R.string.weibo_list_user_id_name), mUser!!.id) + intent.putExtra(getString(R.string.user_list_type_name), UserListActivity.USER_LIST_TYPE_FOLLOWER) + startActivity(intent) + } + (mStatsCard.findViewById(R.id.user_stats_user_des) as TextView).text = mUser!!.description + (mStatsCard.findViewById(R.id.user_stats_follower_count) as TextView).text = mUser!!.followersCount.toString() + (mStatsCard.findViewById(R.id.user_stats_following_count) as TextView).text = mUser!!.friendsCount.toString() + if (!TextUtils.isEmpty(mUser!!.url)) + (mStatsCard.findViewById(R.id.user_stats_url) as TextView).text = mUser!!.url + else + mStatsCard.findViewById(R.id.user_stats_url_box).visibility = View.GONE + if (!TextUtils.isEmpty(mUser!!.location)) + (mStatsCard.findViewById(R.id.user_stats_location) as TextView).text = mUser!!.location + else + mStatsCard.findViewById(R.id.user_stats_location_box).visibility = View.GONE + if (!TextUtils.isEmpty(mUser!!.verifiedReason)) + (mStatsCard.findViewById(R.id.user_verified_reason) as TextView).text = mUser!!.verifiedReason + else + mStatsCard.findViewById(R.id.user_stats_verified_box).visibility = View.GONE + (mStatsCard.findViewById(R.id.user_stats_created_time) as TextView).text = mUser!!.createdAtDiffForHuman + checkForFollowState() + mStatsCard.findViewById(R.id.user_stats_follow_state).setOnClickListener { view -> + mProgressBar.visibility = View.VISIBLE + mStatsCard.findViewById(R.id.user_stats_follow_state).isEnabled = false + if (mUser!!.isFollowing) { + Friends.unfollow(mUser!!.id, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + Toast.makeText(this@UserActivity, "取消关注失败", Toast.LENGTH_SHORT).show() + mProgressBar.visibility = View.GONE + mStatsCard.findViewById(R.id.user_stats_follow_state).isEnabled = true + } + + override fun onResponse(response: UserModel, id: Int) { + mUser!!.isFollowing = !mUser!!.isFollowing + checkForFollowState() + mProgressBar.visibility = View.GONE + mStatsCard.findViewById(R.id.user_stats_follow_state).isEnabled = true + } + }) + } else { + Friends.follow(mUser!!.id, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + Toast.makeText(this@UserActivity, "关注失败", Toast.LENGTH_SHORT).show() + mProgressBar.visibility = View.GONE + mStatsCard.findViewById(R.id.user_stats_follow_state).isEnabled = true + } + + override fun onResponse(response: UserModel, id: Int) { + mUser!!.isFollowing = !mUser!!.isFollowing + checkForFollowState() + mProgressBar.visibility = View.GONE + mStatsCard.findViewById(R.id.user_stats_follow_state).isEnabled = true + } + }) + } + } + Friends.getFollowers(mUser!!.id, 3, 0, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + + } + + override fun onResponse(response: UserListModel, id: Int) { + if (isDestroyed) return + if (response.users!!.isNotEmpty()) + Glide.with(this@UserActivity).load(response.users!![0].avatarLarge).fitCenter().crossFade().into(mStatsCard.findViewById(R.id.user_stats_follower_icon_1) as CircleImageView) + if (response.users!!.size > 1) + Glide.with(this@UserActivity).load(response.users!![1].avatarLarge).fitCenter().crossFade().into(mStatsCard.findViewById(R.id.user_stats_follower_icon_2) as CircleImageView) + if (response.users!!.size > 2) + Glide.with(this@UserActivity).load(response.users!![2].avatarLarge).fitCenter().crossFade().into(mStatsCard.findViewById(R.id.user_stats_follower_icon_3) as CircleImageView) + } + }) + Friends.getFriends(mUser!!.id, 3, 0, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + + } + + override fun onResponse(response: UserListModel, id: Int) { + if (isDestroyed) return + if (response.users!!.isNotEmpty()) + Glide.with(this@UserActivity).load(response.users!![0].avatarLarge).fitCenter().crossFade().into(mStatsCard.findViewById(R.id.user_stats_following_icon_1) as CircleImageView) + if (response.users!!.size > 1) + Glide.with(this@UserActivity).load(response.users!![1].avatarLarge).fitCenter().crossFade().into(mStatsCard.findViewById(R.id.user_stats_following_icon_2) as CircleImageView) + if (response.users!!.size > 2) + Glide.with(this@UserActivity).load(response.users!![2].avatarLarge).fitCenter().crossFade().into(mStatsCard.findViewById(R.id.user_stats_following_icon_3) as CircleImageView) + } + }) + } + + private fun checkForFollowState() { + if (mUser!!.isFollowing && mUser!!.isFollowMe) + (mStatsCard.findViewById(R.id.user_stats_follow_state) as Button).text = "互相关注" + else if (mUser!!.isFollowMe) + (mStatsCard.findViewById(R.id.user_stats_follow_state) as Button).text = "被关注" + else if (mUser!!.isFollowing) + (mStatsCard.findViewById(R.id.user_stats_follow_state) as Button).text = "正在关注" + else if (mUser!!.id === StaticResource.uid) + mStatsCard.findViewById(R.id.user_stats_follow_state).visibility = View.INVISIBLE + else + (mStatsCard.findViewById(R.id.user_stats_follow_state) as Button).text = "关注" + } + + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.activity_user, menu) + mMenu = menu + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (mUser != null) { + when (item.itemId) { + R.id.menu_user_block -> { + val blockUserid = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.block_userid_key), null) + val blockList: MutableList + if (TextUtils.isEmpty(blockUserid)) + blockList = ArrayList() + else + blockList = ArrayList(Arrays.asList(*blockUserid!!.split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray())) + if (!blockList.contains(mUser!!.id.toString())) { + blockList.add(mUser!!.id.toString()) + mMenu!!.findItem(R.id.menu_user_block).title = "已屏蔽" + } else { + blockList.remove(mUser!!.id.toString()) + mMenu!!.findItem(R.id.menu_user_block).title = "屏蔽" + } + PreferenceManager.getDefaultSharedPreferences(this).edit().putString(getString(R.string.block_userid_key), TextUtils.join(",", blockList)).apply() + } + R.id.menu_user_blacklist -> Blocks.addBlock(mUser!!.id, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + + } + + override fun onResponse(response: UserModel, id: Int) { + Toast.makeText(this@UserActivity, "丢进黑名单成功", Toast.LENGTH_SHORT).show() + } + }) + R.id.menu_user_directmessage -> { + val intent = Intent(this, DirectMessageActivity::class.java) + intent.putExtra(getString(R.string.user_item_name), mUser) + startActivity(intent) + } + } + } + return super.onOptionsItemSelected(item) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/activity/UserListActivity.java b/app/src/main/java/moe/tlaster/openween/activity/UserListActivity.java deleted file mode 100644 index f774779..0000000 --- a/app/src/main/java/moe/tlaster/openween/activity/UserListActivity.java +++ /dev/null @@ -1,35 +0,0 @@ -package moe.tlaster.openween.activity; - -import android.os.Bundle; -import android.support.v4.app.FragmentTransaction; - -import moe.tlaster.openween.R; -import moe.tlaster.openween.fragment.user.Follower; -import moe.tlaster.openween.fragment.user.Following; -import moe.tlaster.openween.fragment.user.Timeline; - -/** - * Created by Asahi on 2016/11/3. - */ - -public class UserListActivity extends BaseActivity { - public static final int USER_LIST_TYPE_FOLLOWER = 1; - public static final int USER_LIST_TYPE_FOLLOWING = 2; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_weibo_list); - FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); - switch (getIntent().getExtras().getInt(getString(R.string.user_list_type_name))) { - case USER_LIST_TYPE_FOLLOWER: - setTitle("粉丝"); - fragmentTransaction.add(R.id.weibo_list_fragment_container, Follower.create(getIntent().getExtras().getLong(getString(R.string.weibo_list_user_id_name)))); - break; - case USER_LIST_TYPE_FOLLOWING: - setTitle("关注"); - fragmentTransaction.add(R.id.weibo_list_fragment_container, Following.create(getIntent().getExtras().getLong(getString(R.string.weibo_list_user_id_name)))); - break; - } - fragmentTransaction.commit(); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/activity/UserListActivity.kt b/app/src/main/java/moe/tlaster/openween/activity/UserListActivity.kt new file mode 100644 index 0000000..4471ac5 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/activity/UserListActivity.kt @@ -0,0 +1,37 @@ +package moe.tlaster.openween.activity + +import android.os.Bundle +import android.support.v4.app.FragmentTransaction + +import moe.tlaster.openween.R +import moe.tlaster.openween.fragment.user.Follower +import moe.tlaster.openween.fragment.user.Following +import moe.tlaster.openween.fragment.user.Timeline + +/** + * Created by Asahi on 2016/11/3. + */ + +class UserListActivity : BaseActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_weibo_list) + val fragmentTransaction = supportFragmentManager.beginTransaction() + when (intent.extras.getInt(getString(R.string.user_list_type_name))) { + USER_LIST_TYPE_FOLLOWER -> { + title = "粉丝" + fragmentTransaction.add(R.id.weibo_list_fragment_container, Follower.create(intent.extras.getLong(getString(R.string.weibo_list_user_id_name)))) + } + USER_LIST_TYPE_FOLLOWING -> { + title = "关注" + fragmentTransaction.add(R.id.weibo_list_fragment_container, Following.create(intent.extras.getLong(getString(R.string.weibo_list_user_id_name)))) + } + } + fragmentTransaction.commit() + } + + companion object { + val USER_LIST_TYPE_FOLLOWER = 1 + val USER_LIST_TYPE_FOLLOWING = 2 + } +} diff --git a/app/src/main/java/moe/tlaster/openween/activity/WeiboListActivity.java b/app/src/main/java/moe/tlaster/openween/activity/WeiboListActivity.java deleted file mode 100644 index 4c2e083..0000000 --- a/app/src/main/java/moe/tlaster/openween/activity/WeiboListActivity.java +++ /dev/null @@ -1,23 +0,0 @@ -package moe.tlaster.openween.activity; - -import android.support.v4.app.FragmentTransaction; -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; -import android.widget.FrameLayout; - -import butterknife.BindView; -import butterknife.ButterKnife; -import moe.tlaster.openween.R; -import moe.tlaster.openween.fragment.user.Timeline; - -public class WeiboListActivity extends AppCompatActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_weibo_list); - FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); - Timeline timeline = Timeline.create(getIntent().getExtras().getLong(getString(R.string.weibo_list_user_id_name))); - fragmentTransaction.add(R.id.weibo_list_fragment_container, timeline); - fragmentTransaction.commit(); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/activity/WeiboListActivity.kt b/app/src/main/java/moe/tlaster/openween/activity/WeiboListActivity.kt new file mode 100644 index 0000000..d5da673 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/activity/WeiboListActivity.kt @@ -0,0 +1,22 @@ +package moe.tlaster.openween.activity + +import android.support.v4.app.FragmentTransaction +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.widget.FrameLayout + +import butterknife.BindView +import butterknife.ButterKnife +import moe.tlaster.openween.R +import moe.tlaster.openween.fragment.user.Timeline + +class WeiboListActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_weibo_list) + val fragmentTransaction = supportFragmentManager.beginTransaction() + val timeline = Timeline.create(intent.extras.getLong(getString(R.string.weibo_list_user_id_name))) + fragmentTransaction.add(R.id.weibo_list_fragment_container, timeline) + fragmentTransaction.commit() + } +} diff --git a/app/src/main/java/moe/tlaster/openween/adapter/BaseModelAdapter.java b/app/src/main/java/moe/tlaster/openween/adapter/BaseModelAdapter.java deleted file mode 100644 index 17b196f..0000000 --- a/app/src/main/java/moe/tlaster/openween/adapter/BaseModelAdapter.java +++ /dev/null @@ -1,75 +0,0 @@ -package moe.tlaster.openween.adapter; - -import android.app.Activity; -import android.app.ActivityOptions; -import android.content.Intent; -import android.support.v4.util.Pair; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; - -import com.bumptech.glide.Glide; -import com.chad.library.adapter.base.BaseMultiItemQuickAdapter; -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; -import com.jaeger.ninegridimageview.NineGridImageView; - -import java.util.ArrayList; -import java.util.List; - -import de.hdodenhof.circleimageview.CircleImageView; -import moe.tlaster.openween.R; -import moe.tlaster.openween.activity.DetailActivity; -import moe.tlaster.openween.activity.MainActivity; -import moe.tlaster.openween.activity.PostWeiboActivity; -import moe.tlaster.openween.activity.SplashActivity; -import moe.tlaster.openween.activity.UserActivity; -import moe.tlaster.openween.common.controls.WeiboTextBlock; -import moe.tlaster.openween.common.entities.PostWeiboType; -import moe.tlaster.openween.common.helpers.WeiboCardHelper; -import moe.tlaster.openween.core.model.BaseModel; -import moe.tlaster.openween.core.model.comment.CommentModel; -import moe.tlaster.openween.core.model.status.MessageModel; -import moe.tlaster.openween.core.model.user.UserModel; - -/** - * Created by Asahi on 2016/9/23. - */ - -public class BaseModelAdapter extends BaseQuickAdapter { - - private boolean mIsEnableRepost; - - public BaseModelAdapter() { - this(true); - } - - public BaseModelAdapter(boolean isEnableRepost) { - super(R.layout.base_model_template, null); - mIsEnableRepost = isEnableRepost; - } - - @Override - protected void convert(BaseViewHolder baseViewHolder, BaseModel baseModel) { - if (WeiboCardHelper.shouldBlock(mContext, baseModel)) { - baseViewHolder.setVisible(R.id.base_model_container, false); - return; - } - View baseView = baseViewHolder.getConvertView(); - WeiboCardHelper.setData(baseView, baseModel, mContext, mIsEnableRepost); - if (baseModel instanceof MessageModel) { - baseView.findViewById(R.id.weibo_content_container).findViewById(R.id.weibo_content).setOnClickListener(view -> goDetail((MessageModel) baseModel, baseView)); - if (((MessageModel) baseModel).getRetweetedStatus() != null) - baseView.findViewById(R.id.weibo_repost_container).findViewById(R.id.weibo_content).setOnClickListener(view -> goDetail(((MessageModel) baseModel).getRetweetedStatus(), baseView.findViewById(R.id.weibo_repost_container))); - } - if (baseModel instanceof CommentModel && ((CommentModel) baseModel).getStatus() != null) - baseView.findViewById(R.id.weibo_repost_container).findViewById(R.id.weibo_content).setOnClickListener(view -> goDetail(((CommentModel) baseModel).getStatus(), baseView.findViewById(R.id.weibo_repost_container))); - } - - private void goDetail(MessageModel baseModel, View baseView) { - Intent i = new Intent(mContext, DetailActivity.class); - ActivityOptions transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation((Activity) mContext, baseView, mContext.getString(R.string.base_model_template_name)); - i.putExtra(mContext.getString(R.string.detail_message_model_name), baseModel); - mContext.startActivity(i, transitionActivityOptions.toBundle()); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/adapter/BaseModelAdapter.kt b/app/src/main/java/moe/tlaster/openween/adapter/BaseModelAdapter.kt new file mode 100644 index 0000000..b8767db --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/adapter/BaseModelAdapter.kt @@ -0,0 +1,62 @@ +package moe.tlaster.openween.adapter + +import android.app.Activity +import android.app.ActivityOptions +import android.content.Intent +import android.support.v4.util.Pair +import android.view.View +import android.widget.ImageView +import android.widget.TextView + +import com.bumptech.glide.Glide +import com.chad.library.adapter.base.BaseMultiItemQuickAdapter +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder +import com.jaeger.ninegridimageview.NineGridImageView + +import java.util.ArrayList + +import de.hdodenhof.circleimageview.CircleImageView +import moe.tlaster.openween.R +import moe.tlaster.openween.activity.DetailActivity +import moe.tlaster.openween.activity.MainActivity +import moe.tlaster.openween.activity.PostWeiboActivity +import moe.tlaster.openween.activity.SplashActivity +import moe.tlaster.openween.activity.UserActivity +import moe.tlaster.openween.common.controls.WeiboTextBlock +import moe.tlaster.openween.common.entities.PostWeiboType +import moe.tlaster.openween.common.helpers.WeiboCardHelper +import moe.tlaster.openween.core.model.BaseModel +import moe.tlaster.openween.core.model.comment.CommentModel +import moe.tlaster.openween.core.model.status.MessageModel +import moe.tlaster.openween.core.model.user.UserModel + +/** + * Created by Asahi on 2016/9/23. + */ + +class BaseModelAdapter @JvmOverloads constructor(private val mIsEnableRepost: Boolean = true) : BaseQuickAdapter(R.layout.base_model_template, null) { + + override fun convert(baseViewHolder: BaseViewHolder, p1: T) { + if (WeiboCardHelper.shouldBlock(mContext, p1)) { + baseViewHolder.setVisible(R.id.base_model_container, false) + return + } + val baseView = baseViewHolder.getConvertView() + WeiboCardHelper.setData(baseView, p1, mContext, mIsEnableRepost) + if (p1 is MessageModel) { + baseView.findViewById(R.id.weibo_content_container).findViewById(R.id.weibo_content).setOnClickListener { view -> goDetail(p1, baseView) } + if (p1.retweetedStatus != null) + baseView.findViewById(R.id.weibo_repost_container).findViewById(R.id.weibo_content).setOnClickListener { view -> goDetail(p1.retweetedStatus as MessageModel, baseView.findViewById(R.id.weibo_repost_container)) } + } + if (p1 is CommentModel && p1.status != null) + baseView.findViewById(R.id.weibo_repost_container).findViewById(R.id.weibo_content).setOnClickListener { view -> goDetail(p1.status as MessageModel, baseView.findViewById(R.id.weibo_repost_container)) } + } + + private fun goDetail(p1: MessageModel, baseView: View) { + val i = Intent(mContext, DetailActivity::class.java) + val transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation(mContext as Activity, baseView, mContext.getString(R.string.base_model_template_name)) + i.putExtra(mContext.getString(R.string.detail_message_model_name), p1) + mContext.startActivity(i, transitionActivityOptions.toBundle()) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/adapter/DirectMessageAdapter.java b/app/src/main/java/moe/tlaster/openween/adapter/DirectMessageAdapter.java deleted file mode 100644 index c3c78da..0000000 --- a/app/src/main/java/moe/tlaster/openween/adapter/DirectMessageAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -package moe.tlaster.openween.adapter; - -import android.view.View; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; - -import java.util.List; - -import me.himanshusoni.chatmessageview.ChatMessageView; -import moe.tlaster.openween.R; -import moe.tlaster.openween.common.StaticResource; -import moe.tlaster.openween.core.model.directmessage.DirectMessageModel; - -/** - * Created by Asahi on 2016/11/7. - */ - -public class DirectMessageAdapter extends BaseQuickAdapter { - - public DirectMessageAdapter() { - super(R.layout.direct_message_item_template, null); - } - - @Override - protected void convert(BaseViewHolder baseViewHolder, DirectMessageModel directMessageModel) { - if (directMessageModel.getSenderID() == StaticResource.getUid()) { - baseViewHolder.getView(R.id.direct_message_list_from_me_container).setVisibility(View.VISIBLE); - baseViewHolder.getView(R.id.direct_message_list_from_other_container).setVisibility(View.GONE); - baseViewHolder.setText(R.id.direct_message_list_from_me_text, directMessageModel.getText()); - } else { - baseViewHolder.getView(R.id.direct_message_list_from_me_container).setVisibility(View.GONE); - baseViewHolder.getView(R.id.direct_message_list_from_other_container).setVisibility(View.VISIBLE); - baseViewHolder.setText(R.id.direct_message_list_from_other_text, directMessageModel.getText()); - } - } -} diff --git a/app/src/main/java/moe/tlaster/openween/adapter/DirectMessageAdapter.kt b/app/src/main/java/moe/tlaster/openween/adapter/DirectMessageAdapter.kt new file mode 100644 index 0000000..0bd686e --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/adapter/DirectMessageAdapter.kt @@ -0,0 +1,30 @@ +package moe.tlaster.openween.adapter + +import android.view.View + +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder + +import me.himanshusoni.chatmessageview.ChatMessageView +import moe.tlaster.openween.R +import moe.tlaster.openween.common.StaticResource +import moe.tlaster.openween.core.model.directmessage.DirectMessageModel + +/** + * Created by Asahi on 2016/11/7. + */ + +class DirectMessageAdapter : BaseQuickAdapter(R.layout.direct_message_item_template, null) { + + override fun convert(baseViewHolder: BaseViewHolder, directMessageModel: DirectMessageModel) { + if (directMessageModel.senderID == StaticResource.uid) { + baseViewHolder.getView(R.id.direct_message_list_from_me_container).visibility = View.VISIBLE + baseViewHolder.getView(R.id.direct_message_list_from_other_container).visibility = View.GONE + baseViewHolder.setText(R.id.direct_message_list_from_me_text, directMessageModel.text) + } else { + baseViewHolder.getView(R.id.direct_message_list_from_me_container).visibility = View.GONE + baseViewHolder.getView(R.id.direct_message_list_from_other_container).visibility = View.VISIBLE + baseViewHolder.setText(R.id.direct_message_list_from_other_text, directMessageModel.text) + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/adapter/DirectMessageUserListAdapter.java b/app/src/main/java/moe/tlaster/openween/adapter/DirectMessageUserListAdapter.java deleted file mode 100644 index 9151f01..0000000 --- a/app/src/main/java/moe/tlaster/openween/adapter/DirectMessageUserListAdapter.java +++ /dev/null @@ -1,44 +0,0 @@ -package moe.tlaster.openween.adapter; - -import android.app.Activity; -import android.app.ActivityOptions; -import android.content.Intent; -import android.widget.ImageView; -import android.widget.TextView; - -import com.bumptech.glide.Glide; -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; - -import moe.tlaster.openween.R; -import moe.tlaster.openween.activity.DetailActivity; -import moe.tlaster.openween.activity.DirectMessageActivity; -import moe.tlaster.openween.common.helpers.WeiboCardHelper; -import moe.tlaster.openween.core.model.directmessage.DirectMessageUserModel; - -/** - * Created by Asahi on 2016/11/7. - */ - -public class DirectMessageUserListAdapter extends BaseQuickAdapter { - - public DirectMessageUserListAdapter() { - super(R.layout.user_header_template, null); - } - @Override - protected void convert(BaseViewHolder baseViewHolder, DirectMessageUserModel directMessageUserModel) { - baseViewHolder.setText(R.id.user_name, directMessageUserModel.getUser().getScreenName()); - baseViewHolder.setText(R.id.user_sub_text, directMessageUserModel.getDirectMessage().getText()); - Glide.with(mContext).load(directMessageUserModel.getUser().getAvatarLarge()).into((ImageView) baseViewHolder.getView(R.id.user_img)); - int padding = mContext.getResources().getDimensionPixelSize(R.dimen.dp_10); - ((TextView) baseViewHolder.getView(R.id.user_sub_text)).setLines(1); - baseViewHolder.getConvertView().setPadding(padding, padding, padding, padding); - baseViewHolder.getConvertView().setOnClickListener(view -> { - Intent i = new Intent(mContext, DirectMessageActivity.class); - ActivityOptions transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation((Activity) mContext, baseViewHolder.getConvertView(), mContext.getString(R.string.user_header_name)); - i.putExtra(mContext.getString(R.string.user_item_name), directMessageUserModel.getUser()); - mContext.startActivity(i, transitionActivityOptions.toBundle()); - }); - //baseViewHolder.getConvertView().setOnClickListener(view -> WeiboCardHelper.goUserActivity(userModel.getScreenName(), mContext)); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/adapter/DirectMessageUserListAdapter.kt b/app/src/main/java/moe/tlaster/openween/adapter/DirectMessageUserListAdapter.kt new file mode 100644 index 0000000..b5e0c93 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/adapter/DirectMessageUserListAdapter.kt @@ -0,0 +1,40 @@ +package moe.tlaster.openween.adapter + +import android.app.Activity +import android.app.ActivityOptions +import android.content.Intent +import android.view.View +import android.widget.ImageView +import android.widget.TextView + +import com.bumptech.glide.Glide +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder + +import moe.tlaster.openween.R +import moe.tlaster.openween.activity.DetailActivity +import moe.tlaster.openween.activity.DirectMessageActivity +import moe.tlaster.openween.common.helpers.WeiboCardHelper +import moe.tlaster.openween.core.model.directmessage.DirectMessageUserModel + +/** + * Created by Asahi on 2016/11/7. + */ + +class DirectMessageUserListAdapter : BaseQuickAdapter(R.layout.user_header_template, null) { + override fun convert(baseViewHolder: BaseViewHolder, directMessageUserModel: DirectMessageUserModel) { + baseViewHolder.setText(R.id.user_name, directMessageUserModel.user!!.screenName) + baseViewHolder.setText(R.id.user_sub_text, directMessageUserModel.directMessage!!.text) + Glide.with(mContext).load(directMessageUserModel.user!!.avatarLarge).into(baseViewHolder.getView(R.id.user_img) as ImageView) + val padding = mContext.resources.getDimensionPixelSize(R.dimen.dp_10) + (baseViewHolder.getView(R.id.user_sub_text) as TextView).setLines(1) + baseViewHolder.getConvertView().setPadding(padding, padding, padding, padding) + baseViewHolder.getConvertView().setOnClickListener { view -> + val i = Intent(mContext, DirectMessageActivity::class.java) + val transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation(mContext as Activity, baseViewHolder.getConvertView(), mContext.getString(R.string.user_header_name)) + i.putExtra(mContext.getString(R.string.user_item_name), directMessageUserModel.user) + mContext.startActivity(i, transitionActivityOptions.toBundle()) + } + //baseViewHolder.getConvertView().setOnClickListener(view -> WeiboCardHelper.goUserActivity(userModel.getScreenName(), mContext)); + } +} diff --git a/app/src/main/java/moe/tlaster/openween/adapter/UserListAdapter.java b/app/src/main/java/moe/tlaster/openween/adapter/UserListAdapter.java deleted file mode 100644 index 88c1b43..0000000 --- a/app/src/main/java/moe/tlaster/openween/adapter/UserListAdapter.java +++ /dev/null @@ -1,35 +0,0 @@ -package moe.tlaster.openween.adapter; - -import android.widget.ImageView; -import android.widget.TextView; - -import com.bumptech.glide.Glide; -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; - -import java.util.List; - -import moe.tlaster.openween.R; -import moe.tlaster.openween.common.helpers.WeiboCardHelper; -import moe.tlaster.openween.core.model.user.UserModel; - -/** - * Created by Asahi on 2016/11/3. - */ - -public class UserListAdapter extends BaseQuickAdapter { - public UserListAdapter() { - super(R.layout.user_header_template, null); - } - - @Override - protected void convert(BaseViewHolder baseViewHolder, UserModel userModel) { - baseViewHolder.setText(R.id.user_name, userModel.getScreenName()); - baseViewHolder.setText(R.id.user_sub_text, userModel.getDescription()); - Glide.with(mContext).load(userModel.getAvatarLarge()).into((ImageView) baseViewHolder.getView(R.id.user_img)); - int padding = mContext.getResources().getDimensionPixelSize(R.dimen.dp_10); - ((TextView) baseViewHolder.getView(R.id.user_sub_text)).setLines(1); - baseViewHolder.getConvertView().setPadding(padding, padding, padding, padding); - baseViewHolder.getConvertView().setOnClickListener(view -> WeiboCardHelper.goUserActivity(userModel.getScreenName(), mContext)); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/adapter/UserListAdapter.kt b/app/src/main/java/moe/tlaster/openween/adapter/UserListAdapter.kt new file mode 100644 index 0000000..3c890a2 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/adapter/UserListAdapter.kt @@ -0,0 +1,30 @@ +package moe.tlaster.openween.adapter + +import android.view.View +import android.widget.ImageView +import android.widget.TextView + +import com.bumptech.glide.Glide +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder + +import moe.tlaster.openween.R +import moe.tlaster.openween.common.helpers.WeiboCardHelper +import moe.tlaster.openween.core.model.user.UserModel + +/** + * Created by Asahi on 2016/11/3. + */ + +class UserListAdapter : BaseQuickAdapter(R.layout.user_header_template, null) { + + override fun convert(baseViewHolder: BaseViewHolder, userModel: UserModel) { + baseViewHolder.setText(R.id.user_name, userModel.screenName) + baseViewHolder.setText(R.id.user_sub_text, userModel.description) + Glide.with(mContext).load(userModel.avatarLarge).into(baseViewHolder.getView(R.id.user_img) as ImageView) + val padding = mContext.resources.getDimensionPixelSize(R.dimen.dp_10) + (baseViewHolder.getView(R.id.user_sub_text) as TextView).setLines(1) + baseViewHolder.getConvertView().setPadding(padding, padding, padding, padding) + baseViewHolder.getConvertView().setOnClickListener { view -> WeiboCardHelper.goUserActivity(userModel.screenName!!, mContext) } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/adapter/WeiboImageAdapter.java b/app/src/main/java/moe/tlaster/openween/adapter/WeiboImageAdapter.java deleted file mode 100644 index 647c129..0000000 --- a/app/src/main/java/moe/tlaster/openween/adapter/WeiboImageAdapter.java +++ /dev/null @@ -1,56 +0,0 @@ -package moe.tlaster.openween.adapter; - -import android.content.Context; -import android.content.Intent; -import android.graphics.Color; -import android.net.ConnectivityManager; -import android.net.Network; -import android.net.NetworkInfo; -import android.net.wifi.WifiManager; -import android.widget.ImageView; - -import com.annimon.stream.Collectors; -import com.annimon.stream.Stream; -import com.bumptech.glide.Glide; -import com.bumptech.glide.load.resource.drawable.GlideDrawable; -import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.target.Target; -import com.jaeger.ninegridimageview.NineGridImageViewAdapter; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.IconicsDrawable; -import com.mikepenz.materialdrawer.icons.MaterialDrawerFont; - -import java.util.ArrayList; -import java.util.List; - -import moe.tlaster.openween.common.controls.WeiboImageList; -import moe.tlaster.openween.common.helpers.DeviceHelper; -import moe.tlaster.openween.core.model.status.PictureModel; - -/** - * Created by Tlaster on 2016/9/10. - */ -public class WeiboImageAdapter extends NineGridImageViewAdapter { - @Override - protected void onDisplayImage(Context context, ImageView imageView, PictureModel pictureModel) { - Glide.with(context).load(DeviceHelper.checkWifiOnAndConnected(context) ? pictureModel.toBmiddle() : pictureModel.getThumbnailPic()).placeholder(new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_image).color(Color.GRAY).sizeDp(48)).fitCenter().crossFade().listener(new RequestListener() { - @Override - public boolean onException(Exception e, String model, Target target, boolean isFirstResource) { - imageView.setImageDrawable(new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_mood_bad).color(Color.GRAY).sizeDp(48)); - return false; - } - @Override - public boolean onResourceReady(GlideDrawable resource, String model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { - return false; - } - }).into(imageView); - } - - @Override - protected void onItemImageClick(Context context, int index, List list) { - Intent intent = new Intent(context, WeiboImageList.class); - intent.putStringArrayListExtra(WeiboImageList.INTENTNAME, Stream.of(list).map(PictureModel::toLarge).collect(Collectors.toCollection(ArrayList::new))); - intent.putExtra(WeiboImageList.POSITIONNAME, index); - context.startActivity(intent); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/adapter/WeiboImageAdapter.kt b/app/src/main/java/moe/tlaster/openween/adapter/WeiboImageAdapter.kt new file mode 100644 index 0000000..6e03c9a --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/adapter/WeiboImageAdapter.kt @@ -0,0 +1,51 @@ +package moe.tlaster.openween.adapter + +import android.content.Context +import android.content.Intent +import android.graphics.Color +import android.net.ConnectivityManager +import android.net.Network +import android.net.NetworkInfo +import android.net.wifi.WifiManager +import android.widget.ImageView + + + +import com.bumptech.glide.Glide +import com.bumptech.glide.load.resource.drawable.GlideDrawable +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.target.Target +import com.jaeger.ninegridimageview.NineGridImageViewAdapter +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.IconicsDrawable +import com.mikepenz.materialdrawer.icons.MaterialDrawerFont + +import java.util.ArrayList + +import moe.tlaster.openween.common.controls.WeiboImageList +import moe.tlaster.openween.common.helpers.DeviceHelper +import moe.tlaster.openween.core.model.status.PictureModel + +/** + * Created by Tlaster on 2016/9/10. + */ +class WeiboImageAdapter : NineGridImageViewAdapter() { + override fun onDisplayImage(context: Context, imageView: ImageView, pictureModel: PictureModel) { + Glide.with(context).load(if (DeviceHelper.checkWifiOnAndConnected(context)) pictureModel.toBmiddle() else pictureModel.thumbnailPic).placeholder(IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_image).color(Color.GRAY).sizeDp(48)).fitCenter().crossFade().listener(object : RequestListener { + override fun onException(e: Exception, model: String, target: Target, isFirstResource: Boolean): Boolean { + imageView.setImageDrawable(IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_mood_bad).color(Color.GRAY).sizeDp(48)) + return false + } + + override fun onResourceReady(resource: GlideDrawable, model: String, target: Target, isFromMemoryCache: Boolean, isFirstResource: Boolean): Boolean { + return false + } + }).into(imageView) + } + + override fun onItemImageClick(context: Context?, index: Int, list: List?) { + val intent = Intent(context, WeiboImageList::class.java) + intent.putStringArrayListExtra(WeiboImageList.INTENTNAME, ArrayList(list!!.map { it.toLarge() })) + context!!.startActivity(intent) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/common/Event.kt b/app/src/main/java/moe/tlaster/openween/common/Event.kt new file mode 100644 index 0000000..2ebbadf --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/Event.kt @@ -0,0 +1,11 @@ +package moe.tlaster.openween.common + +/** + * Created by Asahi on 16/11/27. + */ +class Event { + private val handlers = arrayListOf<(Event.(T) -> Unit)>() + operator fun plusAssign(handler: Event.(T) -> Unit) { handlers.add(handler) } + fun minusAssign(handler: Event.(T) -> Unit) { handlers.remove(handler) } + fun invoke(value: T) { for (handler in handlers) handler(value) } +} \ No newline at end of file diff --git a/app/src/main/java/moe/tlaster/openween/common/SimpleDividerItemDecoration.java b/app/src/main/java/moe/tlaster/openween/common/SimpleDividerItemDecoration.java deleted file mode 100644 index b77d86a..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/SimpleDividerItemDecoration.java +++ /dev/null @@ -1,41 +0,0 @@ -package moe.tlaster.openween.common; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.drawable.Drawable; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.RecyclerView; -import android.view.View; - -import moe.tlaster.openween.R; - -/** - * Created by Tlaster on 2016/9/10. - */ -public class SimpleDividerItemDecoration extends RecyclerView.ItemDecoration { - private Drawable mDivider; - - public SimpleDividerItemDecoration(Context context) { - mDivider = ContextCompat.getDrawable(context, R.drawable.line_divider); - } - - @Override - public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { - int left = parent.getPaddingLeft(); - int right = parent.getWidth() - parent.getPaddingRight(); - - int childCount = parent.getChildCount(); - for (int i = 0; i < childCount; i++) { - View child = parent.getChildAt(i); - - RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); - - int top = child.getBottom() + params.bottomMargin; - int bottom = top + mDivider.getIntrinsicHeight(); - - mDivider.setBounds(left, top, right, bottom); - mDivider.draw(c); - } - } -} - diff --git a/app/src/main/java/moe/tlaster/openween/common/SimpleDividerItemDecoration.kt b/app/src/main/java/moe/tlaster/openween/common/SimpleDividerItemDecoration.kt new file mode 100644 index 0000000..f8e9a3e --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/SimpleDividerItemDecoration.kt @@ -0,0 +1,40 @@ +package moe.tlaster.openween.common + +import android.content.Context +import android.graphics.Canvas +import android.graphics.drawable.Drawable +import android.support.v4.content.ContextCompat +import android.support.v7.widget.RecyclerView +import android.view.View + +import moe.tlaster.openween.R + +/** + * Created by Tlaster on 2016/9/10. + */ +class SimpleDividerItemDecoration(context: Context) : RecyclerView.ItemDecoration() { + private val mDivider: Drawable + + init { + mDivider = ContextCompat.getDrawable(context, R.drawable.line_divider) + } + + override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State?) { + val left = parent.paddingLeft + val right = parent.width - parent.paddingRight + + val childCount = parent.childCount + for (i in 0..childCount - 1) { + val child = parent.getChildAt(i) + + val params = child.layoutParams as RecyclerView.LayoutParams + + val top = child.bottom + params.bottomMargin + val bottom = top + mDivider.intrinsicHeight + + mDivider.setBounds(left, top, right, bottom) + mDivider.draw(c) + } + } +} + diff --git a/app/src/main/java/moe/tlaster/openween/common/StaticResource.java b/app/src/main/java/moe/tlaster/openween/common/StaticResource.java deleted file mode 100644 index 2838949..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/StaticResource.java +++ /dev/null @@ -1,30 +0,0 @@ -package moe.tlaster.openween.common; - -import java.util.List; - -import moe.tlaster.openween.core.model.EmotionModel; - -/** - * Created by Asahi on 2016/9/24. - */ - -public class StaticResource { - private static long mUid; - private static List mEmotions; - - public static List getEmotions() { - return mEmotions; - } - - public static void setEmotions(List Emotions) { - StaticResource.mEmotions = Emotions; - } - - public static long getUid() { - return mUid; - } - - public static void setUid(long Uid) { - StaticResource.mUid = Uid; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/common/StaticResource.kt b/app/src/main/java/moe/tlaster/openween/common/StaticResource.kt new file mode 100644 index 0000000..8e8857e --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/StaticResource.kt @@ -0,0 +1,12 @@ +package moe.tlaster.openween.common + +import moe.tlaster.openween.core.model.EmotionModel + +/** + * Created by Asahi on 2016/9/24. + */ + +object StaticResource { + var uid: Long = 0 + var emotions: List? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/common/controls/ExClickableSpan.java b/app/src/main/java/moe/tlaster/openween/common/controls/ExClickableSpan.java deleted file mode 100644 index ee43524..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/controls/ExClickableSpan.java +++ /dev/null @@ -1,24 +0,0 @@ -package moe.tlaster.openween.common.controls; - -import android.graphics.Color; -import android.text.TextPaint; -import android.text.style.ClickableSpan; -import android.view.View; - -/** - * Created by Asahi on 2016/9/23. - */ - -public class ExClickableSpan extends ClickableSpan { - @Override - public void onClick(View widget) { - - } - - @Override - public void updateDrawState(TextPaint ds) { - super.updateDrawState(ds); - ds.setColor(Color.BLUE); - ds.setUnderlineText(false); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/common/controls/ExClickableSpan.kt b/app/src/main/java/moe/tlaster/openween/common/controls/ExClickableSpan.kt new file mode 100644 index 0000000..1dea26f --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/controls/ExClickableSpan.kt @@ -0,0 +1,22 @@ +package moe.tlaster.openween.common.controls + +import android.graphics.Color +import android.text.TextPaint +import android.text.style.ClickableSpan +import android.view.View + +/** + * Created by Asahi on 2016/9/23. + */ + +open class ExClickableSpan : ClickableSpan() { + override fun onClick(widget: View) { + + } + + override fun updateDrawState(ds: TextPaint) { + super.updateDrawState(ds) + ds.color = Color.BLUE + ds.isUnderlineText = false + } +} diff --git a/app/src/main/java/moe/tlaster/openween/common/controls/Pivot.java b/app/src/main/java/moe/tlaster/openween/common/controls/Pivot.java deleted file mode 100644 index 25a5ac9..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/controls/Pivot.java +++ /dev/null @@ -1,198 +0,0 @@ -package moe.tlaster.openween.common.controls; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Color; -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import android.support.design.widget.AppBarLayout; -import android.support.design.widget.CoordinatorLayout; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentStatePagerAdapter; -import android.support.v4.view.ViewPager; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.ImageView; -import android.widget.TableLayout; -import android.widget.TextView; -import android.widget.Toolbar; - -import com.bumptech.glide.Glide; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.IconicsDrawable; -import com.mikepenz.iconics.typeface.IIcon; -import com.mikepenz.materialdrawer.icons.MaterialDrawerFont; -import com.mikepenz.materialize.Materialize; -import com.mikepenz.materialize.MaterializeBuilder; -import com.mikepenz.materialize.color.Material; -import com.zhy.http.okhttp.OkHttpUtils; -import com.zhy.http.okhttp.callback.BitmapCallback; - -import java.util.ArrayList; -import java.util.List; - -import de.hdodenhof.circleimageview.CircleImageView; -import moe.tlaster.openween.R; -import moe.tlaster.openween.fragment.WeiboListBase; -import okhttp3.Call; -import okhttp3.Request; - -/** - * Created by Tlaster on 2016/9/9. - */ -public class Pivot extends CoordinatorLayout { - - private FragmentPageAdapter mAdapter; - - public Pivot(Context context) { - super(context); - initView(context); - } - - public Pivot(Context context, AttributeSet attrs) { - super(context, attrs); - initView(context); - } - - public Pivot(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - initView(context); - } - private void initView(Context context){ - LayoutInflater.from(context).inflate(R.layout.pivot_template, this); - } - - public int getCurrentIndex() { - return ((ViewPager) findViewById(R.id.pivot_container)).getCurrentItem(); - } - - public FragmentPageAdapter getAdapter() { - return mAdapter; - } - - public void setAdapter(FragmentPageAdapter adapter) { - mAdapter = adapter; - initViewPager(adapter); - } - - public CircleImageView getProfileImageView(){ - return (CircleImageView) findViewById(R.id.profile_image); - } - - public TabLayout getTabLayout() { - return (TabLayout) findViewById(R.id.pivot_tabs); - } - - private void initViewPager(FragmentPageAdapter adapter) { - ViewPager viewPager = (ViewPager) findViewById(R.id.pivot_container); - viewPager.setAdapter(adapter); - TabLayout tabLayout = (TabLayout) findViewById(R.id.pivot_tabs); - tabLayout.setupWithViewPager(viewPager); - for (int i = 0; i < tabLayout.getTabCount(); i++) { - TabLayout.Tab tab = tabLayout.getTabAt(i); - tab.setCustomView(adapter.getHeader(i)); - } - tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { - @Override - public void onTabSelected(TabLayout.Tab tab) { - tab.getCustomView().setAlpha(1.f); - } - - @Override - public void onTabUnselected(TabLayout.Tab tab) { - tab.getCustomView().setAlpha(0.37f); - } - - @Override - public void onTabReselected(TabLayout.Tab tab) { - getAdapter().toTop(getCurrentIndex()); - } - }); - setProfileImage(new IconicsDrawable(getContext()) - .icon(GoogleMaterial.Icon.gmd_person) - .color(Color.WHITE) - .sizeDp(24)); - } - - public AppBarLayout getAppBarLayout() { - return ((AppBarLayout) findViewById(R.id.pivot_appbar)); - } - - public void setOffscreenPageLimit(int limit){ - ((ViewPager) findViewById(R.id.pivot_container)).setOffscreenPageLimit(limit); - } - - public void setProfileImageOnClickListener(View.OnClickListener listener){ - findViewById(R.id.profile_image).setOnClickListener(listener); - } - - public void setProfileImage(Drawable drawable){ - ((CircleImageView) findViewById(R.id.profile_image)).setImageDrawable(drawable); - } - - public void setProfileImage(String url){ - CircleImageView circleImageView = (CircleImageView) findViewById(R.id.profile_image); - OkHttpUtils.get().url(url).build().execute(new BitmapCallback() - { - @Override - public void onError(Call call, Exception e, int id) { - } - @Override - public void onResponse(Bitmap response, int id) { - circleImageView.setImageBitmap(response); - } - }); - } - - public static abstract class PivotItemFragment extends Fragment { - public abstract IIcon getIcon(); - } - - public static class FragmentPageAdapter extends FragmentStatePagerAdapter { - - private final Context mContext; - private final List mFragments = new ArrayList<>(); - private final List mIcon = new ArrayList<>(); - - public FragmentPageAdapter(Context context, FragmentManager fm) { - super(fm); - mContext = context; - } - - public void add(WeiboListBase fragment){ - mFragments.add(fragment); - mIcon.add(fragment.getIcon()); - } - - public View getHeader(int position){ - View tab = LayoutInflater.from(mContext).inflate(R.layout.tabbar_view, null); - ImageView img = (ImageView)tab.findViewById(R.id.tabbar_Image); - Drawable icon = new IconicsDrawable(mContext).icon(mIcon.get(position)).color(Color.WHITE).sizeDp(24); - img.setImageDrawable(icon); - tab.setSelected(position == 0); - tab.setAlpha(tab.isSelected() ? 1.f: 0.37f); - return tab; - } - - @Override - public Fragment getItem(int position) { - return mFragments.get(position); - } - - @Override - public int getCount() { - return mFragments.size(); - } - - public void refresh(int currentIndex) { - mFragments.get(currentIndex).refresh(); - } - - void toTop(int currentIndex) { - mFragments.get(currentIndex).toTop(); - } - } -} diff --git a/app/src/main/java/moe/tlaster/openween/common/controls/Pivot.kt b/app/src/main/java/moe/tlaster/openween/common/controls/Pivot.kt new file mode 100644 index 0000000..8a38c8d --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/controls/Pivot.kt @@ -0,0 +1,172 @@ +package moe.tlaster.openween.common.controls + +import android.content.Context +import android.graphics.Bitmap +import android.graphics.Color +import android.graphics.drawable.Drawable +import android.os.Bundle +import android.support.design.widget.AppBarLayout +import android.support.design.widget.CoordinatorLayout +import android.support.design.widget.TabLayout +import android.support.v4.app.Fragment +import android.support.v4.app.FragmentManager +import android.support.v4.app.FragmentStatePagerAdapter +import android.support.v4.view.ViewPager +import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.View +import android.widget.ImageView +import android.widget.TableLayout +import android.widget.TextView +import android.widget.Toolbar + +import com.bumptech.glide.Glide +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.IconicsDrawable +import com.mikepenz.iconics.typeface.IIcon +import com.mikepenz.materialdrawer.icons.MaterialDrawerFont +import com.mikepenz.materialize.Materialize +import com.mikepenz.materialize.MaterializeBuilder +import com.mikepenz.materialize.color.Material +import com.zhy.http.okhttp.OkHttpUtils +import com.zhy.http.okhttp.callback.BitmapCallback + +import java.util.ArrayList + +import de.hdodenhof.circleimageview.CircleImageView +import moe.tlaster.openween.R +import moe.tlaster.openween.fragment.WeiboListBase +import okhttp3.Call +import okhttp3.Request + +/** + * Created by Tlaster on 2016/9/9. + */ +class Pivot : CoordinatorLayout { + + var adapter: FragmentPageAdapter? = null + set(adapter) { + field = adapter + initViewPager(adapter!!) + } + + constructor(context: Context) : super(context) { + initView(context) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + initView(context) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + initView(context) + } + + private fun initView(context: Context) { + LayoutInflater.from(context).inflate(R.layout.pivot_template, this) + } + + val currentIndex: Int + get() = (findViewById(R.id.pivot_container) as ViewPager).currentItem + + val profileImageView: CircleImageView + get() = findViewById(R.id.profile_image) as CircleImageView + + val tabLayout: TabLayout + get() = findViewById(R.id.pivot_tabs) as TabLayout + + private fun initViewPager(adapter: FragmentPageAdapter) { + val viewPager = findViewById(R.id.pivot_container) as ViewPager + viewPager.adapter = adapter + val tabLayout = findViewById(R.id.pivot_tabs) as TabLayout + tabLayout.setupWithViewPager(viewPager) + for (i in 0..tabLayout.tabCount - 1) { + val tab = tabLayout.getTabAt(i) + tab!!.customView = adapter.getHeader(i) + } + tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { + override fun onTabSelected(tab: TabLayout.Tab) { + tab.customView!!.alpha = 1f + } + + override fun onTabUnselected(tab: TabLayout.Tab) { + tab.customView!!.alpha = 0.37f + } + + override fun onTabReselected(tab: TabLayout.Tab) { + adapter.toTop(currentIndex) + } + }) + setProfileImage(IconicsDrawable(context) + .icon(GoogleMaterial.Icon.gmd_person) + .color(Color.WHITE) + .sizeDp(24)) + } + + val appBarLayout: AppBarLayout + get() = findViewById(R.id.pivot_appbar) as AppBarLayout + + fun setOffscreenPageLimit(limit: Int) { + (findViewById(R.id.pivot_container) as ViewPager).offscreenPageLimit = limit + } + + fun setProfileImageOnClickListener(listener: (Any) -> Unit) { + findViewById(R.id.profile_image).setOnClickListener(listener) + } + + fun setProfileImage(drawable: Drawable) { + (findViewById(R.id.profile_image) as CircleImageView).setImageDrawable(drawable) + } + + fun setProfileImage(url: String) { + val circleImageView = findViewById(R.id.profile_image) as CircleImageView + OkHttpUtils.get().url(url).build().execute(object : BitmapCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + } + + override fun onResponse(response: Bitmap, id: Int) { + circleImageView.setImageBitmap(response) + } + }) + } + + abstract class PivotItemFragment : Fragment() { + abstract val icon: IIcon + } + + class FragmentPageAdapter(private val mContext: Context, fm: FragmentManager) : FragmentStatePagerAdapter(fm) { + private val mFragments = ArrayList>() + private val mIcon = ArrayList() + + fun add(fragment: WeiboListBase<*>) { + mFragments.add(fragment) + mIcon.add(fragment.icon) + } + + fun getHeader(position: Int): View { + val tab = LayoutInflater.from(mContext).inflate(R.layout.tabbar_view, null) + val img = tab.findViewById(R.id.tabbar_Image) as ImageView + val icon = IconicsDrawable(mContext).icon(mIcon[position]).color(Color.WHITE).sizeDp(24) + img.setImageDrawable(icon) + tab.isSelected = position == 0 + tab.alpha = if (tab.isSelected) 1f else 0.37f + return tab + } + + override fun getItem(position: Int): Fragment { + return mFragments[position] + } + + override fun getCount(): Int { + return mFragments.size + } + + fun refresh(currentIndex: Int) { + mFragments[currentIndex].refresh() + } + + internal fun toTop(currentIndex: Int) { + mFragments[currentIndex].toTop() + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/common/controls/WeiboImageList.java b/app/src/main/java/moe/tlaster/openween/common/controls/WeiboImageList.java deleted file mode 100644 index 4eee017..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/controls/WeiboImageList.java +++ /dev/null @@ -1,99 +0,0 @@ -package moe.tlaster.openween.common.controls; - -import android.content.Context; -import android.graphics.Color; -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.view.PagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v7.app.AppCompatActivity; -import android.util.DisplayMetrics; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.load.resource.drawable.GlideDrawable; -import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.target.Target; -import com.goka.flickableview.FlickableImageView; -import com.liuguangqiang.swipeback.SwipeBackActivity; -import com.liuguangqiang.swipeback.SwipeBackLayout; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.IconicsDrawable; - -import java.util.List; - -import me.relex.circleindicator.CircleIndicator; -import moe.tlaster.openween.R; -import moe.tlaster.openween.activity.BaseActivity; - -/** - * Created by Asahi on 2016/9/24. - */ - -public class WeiboImageList extends BaseActivity { - public static String INTENTNAME = "images"; - public static String POSITIONNAME = "position"; - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.weibo_image_list); - ViewPager viewPager = (ViewPager) findViewById(R.id.weibo_image_viewPager); - CircleIndicator indicator = (CircleIndicator) findViewById(R.id.weibo_image_indicator); - viewPager.setAdapter(new ImagePagerAdapter(getIntent().getExtras().getStringArrayList(INTENTNAME))); - indicator.setViewPager(viewPager); - viewPager.post(()-> viewPager.setCurrentItem(getIntent().getIntExtra(POSITIONNAME, 0), false)); - } - - - - class ImagePagerAdapter extends PagerAdapter { - private List mData; - - ImagePagerAdapter(List data) { - mData = data; - } - - @Override - public int getCount() { - return mData.size(); - } - - @Override - public Object instantiateItem(ViewGroup container, int position) { - View itemTemplate = LayoutInflater.from(WeiboImageList.this).inflate(R.layout.weibo_image_list_itemtemplate, container, false); - FlickableImageView imageView = (FlickableImageView) itemTemplate.findViewById(R.id.weibo_image_list_item); - imageView.setOnSingleTapListener(WeiboImageList.this::finish); - imageView.setOnFlickListener(new FlickableImageView.OnFlickableImageViewFlickListener() { - @Override - public void onStartFlick() { - - } - - @Override - public void onFinishFlick() { - WeiboImageList.this.finish(); - } - }); - Glide.with(WeiboImageList.this).load(mData.get(position)).placeholder(new IconicsDrawable(WeiboImageList.this).icon(GoogleMaterial.Icon.gmd_image).color(Color.GRAY).sizeDp(48)).fitCenter().crossFade().into(imageView); - container.addView(itemTemplate); - return itemTemplate; - } - - @Override - public boolean isViewFromObject(View view, Object object) { - return view == object; - } - - @Override - public void destroyItem(ViewGroup container, int position, Object object) { - (container).removeView((View) object); - } - } -} diff --git a/app/src/main/java/moe/tlaster/openween/common/controls/WeiboImageList.kt b/app/src/main/java/moe/tlaster/openween/common/controls/WeiboImageList.kt new file mode 100644 index 0000000..21bb2b8 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/controls/WeiboImageList.kt @@ -0,0 +1,86 @@ +package moe.tlaster.openween.common.controls + +import android.content.Context +import android.graphics.Color +import android.os.Bundle +import android.support.v4.app.Fragment +import android.support.v4.app.FragmentPagerAdapter +import android.support.v4.view.PagerAdapter +import android.support.v4.view.ViewPager +import android.support.v7.app.AppCompatActivity +import android.util.DisplayMetrics +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout + +import com.bumptech.glide.Glide +import com.bumptech.glide.load.resource.drawable.GlideDrawable +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.target.Target +import com.goka.flickableview.FlickableImageView +import com.liuguangqiang.swipeback.SwipeBackActivity +import com.liuguangqiang.swipeback.SwipeBackLayout +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.IconicsDrawable + +import me.relex.circleindicator.CircleIndicator +import moe.tlaster.openween.R +import moe.tlaster.openween.activity.BaseActivity + +/** + * Created by Asahi on 2016/9/24. + */ + +class WeiboImageList : BaseActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.weibo_image_list) + val viewPager = findViewById(R.id.weibo_image_viewPager) as ViewPager + val indicator = findViewById(R.id.weibo_image_indicator) as CircleIndicator + viewPager.adapter = ImagePagerAdapter(intent.extras.getStringArrayList(INTENTNAME)) + indicator.setViewPager(viewPager) + viewPager.post { viewPager.setCurrentItem(intent.getIntExtra(POSITIONNAME, 0), false) } + } + + + internal inner class ImagePagerAdapter(private val mData: List) : PagerAdapter() { + + override fun getCount(): Int { + return mData.size + } + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val itemTemplate = LayoutInflater.from(this@WeiboImageList).inflate(R.layout.weibo_image_list_itemtemplate, container, false) + val imageView = itemTemplate.findViewById(R.id.weibo_image_list_item) as FlickableImageView + imageView.setOnSingleTapListener{ this@WeiboImageList.finish() } + imageView.setOnFlickListener(object : FlickableImageView.OnFlickableImageViewFlickListener { + override fun onStartFlick() { + + } + + override fun onFinishFlick() { + this@WeiboImageList.finish() + } + }) + Glide.with(this@WeiboImageList).load(mData[position]).placeholder(IconicsDrawable(this@WeiboImageList).icon(GoogleMaterial.Icon.gmd_image).color(Color.GRAY).sizeDp(48)).fitCenter().crossFade().into(imageView) + container.addView(itemTemplate) + return itemTemplate + } + + override fun isViewFromObject(view: View, `object`: Any): Boolean { + return view === `object` + } + + override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) { + container.removeView(`object` as View) + } + } + + companion object { + var INTENTNAME = "images" + var POSITIONNAME = "position" + } +} diff --git a/app/src/main/java/moe/tlaster/openween/common/controls/WeiboTextBlock.java b/app/src/main/java/moe/tlaster/openween/common/controls/WeiboTextBlock.java deleted file mode 100644 index cecf4a2..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/controls/WeiboTextBlock.java +++ /dev/null @@ -1,227 +0,0 @@ -package moe.tlaster.openween.common.controls; - -import android.content.Context; -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Color; -import android.net.Uri; -import android.text.Spannable; -import android.text.SpannableString; -import android.text.TextUtils; -import android.text.method.LinkMovementMethod; -import android.text.style.ForegroundColorSpan; -import android.text.style.ImageSpan; -import android.util.AttributeSet; -import android.view.View; -import android.widget.TextView; - -import com.annimon.stream.Collectors; -import com.annimon.stream.Stream; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Objects; -import java.util.concurrent.Callable; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import moe.tlaster.openween.common.StaticResource; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.api.shortUrl.ShortUrl; -import moe.tlaster.openween.core.model.status.PictureModel; -import moe.tlaster.openween.core.model.url.UrlInfoListModel; -import moe.tlaster.openween.core.model.url.UrlInfoModel; -import okhttp3.Call; - -/** - * Created by Asahi on 2016/9/24. - */ - -public class WeiboTextBlock extends TextView { - - private OnClickListener mOnClickListener; - private boolean mCanClick = true; - - public interface WeiboTextCallback{ - void call(String data); - } - - private static final String AT = "@[^,\uff0c\uff1a:\\s@]+"; - private static final String TOPIC = "#[^#]+#"; - private static final String EMOJI = "\\[[\\w]+\\]"; - private static final String URL = "http://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"; - private static final String REGEX = "(" + AT + ")|(" + TOPIC + ")|(" + EMOJI + ")|(" + URL + ")"; - private static final Pattern pattern = Pattern.compile(REGEX); - private WeiboTextCallback mUserClicked; - private WeiboTextCallback mLinkClicked; - private WeiboTextCallback mTopicClicked; - - public WeiboTextCallback getUserClicked() { - return mUserClicked; - } - - public void setUserClicked(WeiboTextCallback userClicked) { - mUserClicked = userClicked; - } - - public WeiboTextCallback getLinkClicked() { - return mLinkClicked; - } - - public void setLinkClicked(WeiboTextCallback linkClicked) { - mLinkClicked = linkClicked; - } - - public WeiboTextCallback getTopicClicked() { - return mTopicClicked; - } - - public void setTopicClicked(WeiboTextCallback topicClicked) { - mTopicClicked = topicClicked; - } - - public WeiboTextBlock(Context context) { - super(context); - } - - public WeiboTextBlock(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public WeiboTextBlock(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @Override - public void setOnClickListener(OnClickListener l) { - mOnClickListener = view -> { - if (mCanClick) - l.onClick(view); - else - mCanClick = true; - }; - super.setOnClickListener(mOnClickListener); - } - - @Override - public void setText(CharSequence text, BufferType type) { - SpannableString spannableString; - int index = text.toString().indexOf("\u5168\u6587\uff1a http://m.weibo.cn/"); - if (index != -1){ - int length = index + 2; - spannableString = new SpannableString(text.toString().substring(0, length)); - ForegroundColorSpan span = new ForegroundColorSpan(Color.BLUE); - spannableString.setSpan(span, index, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - } else { - spannableString = new SpannableString(text); - } - Matcher matcher = pattern.matcher(spannableString); - if (matcher.find()) { - setMovementMethod(LinkMovementMethod.getInstance()); - matcher.reset(); - } - - while (matcher.find()) { - final String at = matcher.group(1); - final String topic = matcher.group(2); - String emoji = matcher.group(3); - final String url = matcher.group(4); - if (at != null) { - int start = matcher.start(1); - int end = start + at.length(); - ExClickableSpan clickableSpan = new ExClickableSpan() { - @Override - public void onClick(View widget) { - if (mUserClicked != null) { - mUserClicked.call(at.substring(1)); - } - } - }; - spannableString.setSpan(clickableSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - } - - if (topic != null) { - int start = matcher.start(2); - int end = start + topic.length(); - ExClickableSpan clickableSpan = new ExClickableSpan() { - @Override - public void onClick(View widget) { - if (mTopicClicked != null) { - mTopicClicked.call(topic); - } - } - }; - spannableString.setSpan(clickableSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - } - - if (emoji != null) { - int start = matcher.start(3); - int end = start + emoji.length(); - try { - String filePath = Stream.of(StaticResource.getEmotions()).filter(item -> Objects.equals(item.getValue(), emoji)).findFirst().get().getUrl(); - Bitmap bitmap = BitmapFactory.decodeFile(filePath); - if (bitmap != null) { - int size = (int) getTextSize(); - bitmap = Bitmap.createScaledBitmap(bitmap, size, size, true); - ImageSpan imageSpan = new ImageSpan(getContext(), bitmap, ImageSpan.ALIGN_BASELINE); - spannableString.setSpan(imageSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - } - } catch (Exception e) { - } - } - - if (url != null) { - int start = matcher.start(4); - int end = start + url.length(); - ExClickableSpan clickableSpan = new ExClickableSpan() { - @Override - public void onClick(View widget) { - mCanClick = false; - if(mLinkClicked != null) - mLinkClicked.call(url); - ShortUrl.info(new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - openLink(url); - } - @Override - public void onResponse(UrlInfoListModel response, int id) { - UrlInfoModel item = response.getUrls().get(0); - switch (item.getType()){ - case 39: { - try { - String picid = item.getAnnotations().get(0).getItem().getPicIds()[0]; - if (!TextUtils.isEmpty(picid)) { - Intent intent = new Intent(getContext(), WeiboImageList.class); - intent.putStringArrayListExtra(WeiboImageList.INTENTNAME, new ArrayList(){{add("http://ww1.sinaimg.cn/large/"+picid+".jpg");}}); - getContext().startActivity(intent); - } - } catch (Exception e) { - //Do nothing - openLink(item.getUrlLong()); - } - } - break; - default: - openLink(item.getUrlLong()); - break; - } - } - }, url); - } - }; - spannableString.setSpan(clickableSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - } - } - super.setText(spannableString, type); - } - - private void openLink(String url) { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(url)); - getContext().startActivity(intent); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/common/controls/WeiboTextBlock.kt b/app/src/main/java/moe/tlaster/openween/common/controls/WeiboTextBlock.kt new file mode 100644 index 0000000..f297e31 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/controls/WeiboTextBlock.kt @@ -0,0 +1,189 @@ +package moe.tlaster.openween.common.controls + +import android.content.Context +import android.content.Intent +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.graphics.Color +import android.net.Uri +import android.text.Spannable +import android.text.SpannableString +import android.text.TextUtils +import android.text.method.LinkMovementMethod +import android.text.style.ForegroundColorSpan +import android.text.style.ImageSpan +import android.util.AttributeSet +import android.view.View +import android.widget.TextView + + + +import moe.tlaster.openween.common.Event + +import java.io.File +import java.util.ArrayList +import java.util.NoSuchElementException +import java.util.Objects +import java.util.concurrent.Callable +import java.util.regex.Matcher +import java.util.regex.Pattern + +import moe.tlaster.openween.common.StaticResource +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.api.shortUrl.ShortUrl +import moe.tlaster.openween.core.model.status.PictureModel +import moe.tlaster.openween.core.model.url.UrlInfoListModel +import moe.tlaster.openween.core.model.url.UrlInfoModel +import okhttp3.Call +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +/** + * Created by Asahi on 2016/9/24. + */ + +class WeiboTextBlock : TextView { + + private var mOnClickListener: View.OnClickListener? = null + private var mCanClick = true + + var userClicked = Event() + var linkClicked = Event() + var topicClicked = Event() + constructor(context: Context) : super(context) { + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + } + + override fun setOnClickListener(l: View.OnClickListener) { + mOnClickListener = View.OnClickListener { view -> + if (mCanClick) + l.onClick(view) + else + mCanClick = true + } + super.setOnClickListener(mOnClickListener) + } + + override fun setText(text: CharSequence, type: TextView.BufferType) { + val spannableString: SpannableString + val index = text.toString().indexOf("\u5168\u6587\uff1a http://m.weibo.cn/") + if (index != -1) { + val length = index + 2 + spannableString = SpannableString(text.toString().substring(0, length)) + val span = ForegroundColorSpan(Color.BLUE) + spannableString.setSpan(span, index, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) + } else { + spannableString = SpannableString(text) + } + val matcher = pattern.matcher(spannableString) + if (matcher.find()) { + movementMethod = LinkMovementMethod.getInstance() + matcher.reset() + } + + while (matcher.find()) { + val at = matcher.group(1) + val topic = matcher.group(2) + val emoji = matcher.group(3) + val url = matcher.group(4) + if (at != null) { + val start = matcher.start(1) + val end = start + at.length + val clickableSpan = object : ExClickableSpan() { + override fun onClick(widget: View) { + userClicked.invoke(at.substring(1)) + } + } + spannableString.setSpan(clickableSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) + } + + if (topic != null) { + val start = matcher.start(2) + val end = start + topic.length + val clickableSpan = object : ExClickableSpan() { + override fun onClick(widget: View) { + topicClicked.invoke(topic) + } + } + spannableString.setSpan(clickableSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) + } + + if (emoji != null) { + val start = matcher.start(3) + val end = start + emoji.length + try { + val filePath = StaticResource.emotions?.filter { it.value == emoji }?.firstOrNull()?.url + var bitmap: Bitmap? = BitmapFactory.decodeFile(filePath) + if (bitmap != null) { + val size = textSize.toInt() + bitmap = Bitmap.createScaledBitmap(bitmap, size, size, true) + val imageSpan = ImageSpan(context, bitmap, ImageSpan.ALIGN_BASELINE) + spannableString.setSpan(imageSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) + } + } catch (e: Exception) { + } + + } + + if (url != null) { + val start = matcher.start(4) + val end = start + url.length + val clickableSpan = object : ExClickableSpan() { + override fun onClick(widget: View) { + mCanClick = false + linkClicked.invoke(url) + ShortUrl.info(object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + openLink(url) + } + + override fun onResponse(response: UrlInfoListModel, id: Int) { + val item = response.urls?.firstOrNull() ?: return + when (item.type) { + 39 -> { + val picid = item.annotations?.firstOrNull()?.item?.picIds?.firstOrNull() + if (!TextUtils.isEmpty(picid)) { + val intent = Intent(context, WeiboImageList::class.java) + intent.putStringArrayListExtra(WeiboImageList.INTENTNAME, object : ArrayList() { + init { + add("http://ww1.sinaimg.cn/large/$picid.jpg") + } + }) + context.startActivity(intent) + } else { + openLink(item.urlLong!!) + } + } + else -> openLink(item.urlLong!!) + } + } + }, url) + } + } + spannableString.setSpan(clickableSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) + } + } + super.setText(spannableString, type) + } + + private fun openLink(url: String) { + val intent = Intent(Intent.ACTION_VIEW) + intent.data = Uri.parse(url) + context.startActivity(intent) + } + + companion object { + + private val AT = "@[^,\uff0c\uff1a:\\s@]+" + private val TOPIC = "#[^#]+#" + private val EMOJI = "\\[[\\w]+\\]" + private val URL = "http://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]" + private val REGEX = "($AT)|($TOPIC)|($EMOJI)|($URL)" + private val pattern = Pattern.compile(REGEX) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/common/entities/PostWeiboType.java b/app/src/main/java/moe/tlaster/openween/common/entities/PostWeiboType.java deleted file mode 100644 index 983d44c..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/entities/PostWeiboType.java +++ /dev/null @@ -1,15 +0,0 @@ -package moe.tlaster.openween.common.entities; - -import android.os.Parcelable; - -/** - * Created by Asahi on 2016/10/5. - */ - -public enum PostWeiboType { - NewPost, - RePost, - Comment, - ReplyComment, -} - diff --git a/app/src/main/java/moe/tlaster/openween/common/entities/PostWeiboType.kt b/app/src/main/java/moe/tlaster/openween/common/entities/PostWeiboType.kt new file mode 100644 index 0000000..8479228 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/entities/PostWeiboType.kt @@ -0,0 +1,15 @@ +package moe.tlaster.openween.common.entities + +import android.os.Parcelable + +/** + * Created by Asahi on 2016/10/5. + */ + +enum class PostWeiboType { + NewPost, + RePost, + Comment, + ReplyComment +} + diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/DeviceHelper.java b/app/src/main/java/moe/tlaster/openween/common/helpers/DeviceHelper.java deleted file mode 100644 index 4f66ed9..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/helpers/DeviceHelper.java +++ /dev/null @@ -1,93 +0,0 @@ -package moe.tlaster.openween.common.helpers; - -import android.content.Context; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; - -import com.zhy.http.okhttp.OkHttpUtils; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import okhttp3.Response; - -/** - * Created by Asahi on 2016/9/27. - */ - -public final class DeviceHelper { - public static boolean checkWifiOnAndConnected(Context context) { - WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); - if (wifiMgr.isWifiEnabled()) { - WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); - return wifiInfo.getNetworkId() != -1; - } else { - return false; - } - } - public static void deleteRecursive(File fileOrDirectory) { - if (fileOrDirectory.isDirectory()) - for (File child : fileOrDirectory.listFiles()) - deleteRecursive(child); - - fileOrDirectory.delete(); - } - - public static String readFromFile(String pathName) { - String ret = ""; - try { - File file = new File(pathName); - InputStream inputStream = new FileInputStream(file); - InputStreamReader inputStreamReader = new InputStreamReader(inputStream); - BufferedReader bufferedReader = new BufferedReader(inputStreamReader); - String receiveString; - StringBuilder stringBuilder = new StringBuilder(); - while ((receiveString = bufferedReader.readLine()) != null) { - stringBuilder.append(receiveString); - } - inputStream.close(); - ret = stringBuilder.toString(); - } - catch (FileNotFoundException e) { - } catch (IOException e) { - } - return ret; - } - - public static File saveFile(Response response, String destFileDir, String destFileName) throws IOException { - InputStream is = null; - byte[] buf = new byte[2048]; - int len = 0; - FileOutputStream fos = null; - try { - is = response.body().byteStream(); - File dir = new File(destFileDir); - if (!dir.exists()) { - dir.mkdirs(); - } - File file = new File(dir, destFileName); - fos = new FileOutputStream(file); - while ((len = is.read(buf)) != -1) { - fos.write(buf, 0, len); - } - fos.flush(); - return file; - } finally { - try { - response.body().close(); - if (is != null) is.close(); - } catch (IOException e) { - } - try { - if (fos != null) fos.close(); - } catch (IOException e) { - } - } - } -} diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/DeviceHelper.kt b/app/src/main/java/moe/tlaster/openween/common/helpers/DeviceHelper.kt new file mode 100644 index 0000000..0d11beb --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/helpers/DeviceHelper.kt @@ -0,0 +1,93 @@ +package moe.tlaster.openween.common.helpers + +import android.content.Context +import android.net.wifi.WifiInfo +import android.net.wifi.WifiManager + +import com.zhy.http.okhttp.OkHttpUtils + +import java.io.BufferedReader +import java.io.File +import java.io.FileInputStream +import java.io.FileNotFoundException +import java.io.FileOutputStream +import java.io.IOException +import java.io.InputStream +import java.io.InputStreamReader + +import okhttp3.Response + +/** + * Created by Asahi on 2016/9/27. + */ + +object DeviceHelper { + fun checkWifiOnAndConnected(context: Context): Boolean { + val wifiMgr = context.getSystemService(Context.WIFI_SERVICE) as WifiManager + if (wifiMgr.isWifiEnabled) { + val wifiInfo = wifiMgr.connectionInfo + return wifiInfo.networkId != -1 + } else { + return false + } + } + + fun deleteRecursive(fileOrDirectory: File) { + if (fileOrDirectory.isDirectory) + for (child in fileOrDirectory.listFiles()) + deleteRecursive(child) + + fileOrDirectory.delete() + } + + fun readFromFile(pathName: String): String { + var ret = "" + try { + val file = File(pathName) + val inputStream = FileInputStream(file) + val inputStreamReader = InputStreamReader(inputStream) + val bufferedReader = BufferedReader(inputStreamReader) + val stringBuilder = StringBuilder() + bufferedReader.readLines().forEach { stringBuilder.append(it) } + inputStream.close() + ret = stringBuilder.toString() + } catch (e: FileNotFoundException) { + } catch (e: IOException) { + } + return ret + } + +// @Throws(IOException::class) +// fun saveFile(response: Response, destFileDir: String, destFileName: String): File { +// var `is`: InputStream? = null +// val buf = ByteArray(2048) +// var len = 0 +// var fos: FileOutputStream? = null +// try { +// `is` = response.body().byteStream() +// val dir = File(destFileDir) +// if (!dir.exists()) { +// dir.mkdirs() +// } +// val file = File(dir, destFileName) +// fos = FileOutputStream(file) +// while ((len = `is`!!.read(buf)) != -1) { +// fos.write(buf, 0, len) +// } +// fos.flush() +// return file +// } finally { +// try { +// response.body().close() +// if (`is` != null) `is`.close() +// } catch (e: IOException) { +// } +// +// try { +// if (fos != null) fos.close() +// } catch (e: IOException) { +// } +// +// } +// } +} diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/HttpHelper.java b/app/src/main/java/moe/tlaster/openween/common/helpers/HttpHelper.java deleted file mode 100644 index c1a7a6b..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/helpers/HttpHelper.java +++ /dev/null @@ -1,60 +0,0 @@ -package moe.tlaster.openween.common.helpers; - -import android.support.annotation.NonNull; -import android.text.TextUtils; - -import com.zhy.http.okhttp.OkHttpUtils; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Entity; - -/** - * Created by Tlaster on 2016/9/5. - */ -public class HttpHelper { - public static void getAsync(String url, Map param, @NonNull JsonCallback callback) { - if (TextUtils.isEmpty(Entity.getAccessToken())){ - callback.onError(null, new InvalidAccessTokenException(), -1); - return; - } - getAsync(url, Entity.getAccessToken(), param, callback); - } - - public static void getAsync(String url, String token, Map param, @NonNull JsonCallback callback){ - if (param == null) param = new HashMap<>(); - param.put("access_token", token); - OkHttpUtils.get().url(url).params(param).build().execute(callback); - } - - public static void postAsync(String url, Map data, @NonNull JsonCallback callback) { - if (TextUtils.isEmpty(Entity.getAccessToken())){ - callback.onError(null, new InvalidAccessTokenException(), -1); - return; - } - if (data == null) data = new HashMap<>(); - data.put("access_token", Entity.getAccessToken()); - OkHttpUtils.post().url(url).params(data).build().execute(callback); - } - - public static void uploadFileAsync(String url, File file, @NonNull JsonCallback callback) { - if (TextUtils.isEmpty(Entity.getAccessToken())){ - callback.onError(null, new InvalidAccessTokenException(), -1); - return; - } - OkHttpUtils.post().url(url).addFile("pic","pic.png",file).addParams("access_token", Entity.getAccessToken()).build().execute(callback); - } - - public static void uploadFileWithParamAsync(String url, File file, Map data, @NonNull JsonCallback callback) { - if (TextUtils.isEmpty(Entity.getAccessToken())){ - callback.onError(null, new InvalidAccessTokenException(), -1); - return; - } - if (data == null) data = new HashMap<>(); - data.put("access_token", Entity.getAccessToken()); - OkHttpUtils.post().url(url).addFile("pic","pic.png",file).params(data).build().execute(callback); - } -} - diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/HttpHelper.kt b/app/src/main/java/moe/tlaster/openween/common/helpers/HttpHelper.kt new file mode 100644 index 0000000..249883d --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/helpers/HttpHelper.kt @@ -0,0 +1,61 @@ +package moe.tlaster.openween.common.helpers + +import android.text.TextUtils + +import com.zhy.http.okhttp.OkHttpUtils + +import java.io.File +import java.util.HashMap + +import moe.tlaster.openween.core.api.Entity + +/** + * Created by Tlaster on 2016/9/5. + */ +object HttpHelper { + fun getAsync(url: String, param: MutableMap?, callback: JsonCallback<*>) { + if (TextUtils.isEmpty(Entity.accessToken)) { + callback.onError(null, InvalidAccessTokenException(), -1) + return + } + getAsync(url, Entity.accessToken!!, param, callback) + } + + fun getAsync(url: String, token: String, param: MutableMap?, callback: JsonCallback<*>) { + var param = param + if (param == null) param = HashMap() + param.put("access_token", token) + OkHttpUtils.get().url(url).params(param).build().execute(callback) + } + + fun postAsync(url: String, data: MutableMap?, callback: JsonCallback<*>?) { + var data = data + if (TextUtils.isEmpty(Entity.accessToken)) { + callback?.onError(null, InvalidAccessTokenException(), -1) + return + } + if (data == null) data = HashMap() + data.put("access_token", Entity.accessToken!!) + OkHttpUtils.post().url(url).params(data).build().execute(callback) + } + + fun uploadFileAsync(url: String, file: File, callback: JsonCallback<*>) { + if (TextUtils.isEmpty(Entity.accessToken)) { + callback.onError(null, InvalidAccessTokenException(), -1) + return + } + OkHttpUtils.post().url(url).addFile("pic", "pic.png", file).addParams("access_token", Entity.accessToken).build().execute(callback) + } + + fun uploadFileWithParamAsync(url: String, file: File, data: MutableMap?, callback: JsonCallback<*>) { + var data = data + if (TextUtils.isEmpty(Entity.accessToken)) { + callback.onError(null, InvalidAccessTokenException(), -1) + return + } + if (data == null) data = HashMap() + data.put("access_token", Entity.accessToken!!) + OkHttpUtils.post().url(url).addFile("pic", "pic.png", file).params(data).build().execute(callback) + } +} + diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/InvalidAccessTokenException.java b/app/src/main/java/moe/tlaster/openween/common/helpers/InvalidAccessTokenException.java deleted file mode 100644 index 3355173..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/helpers/InvalidAccessTokenException.java +++ /dev/null @@ -1,5 +0,0 @@ -package moe.tlaster.openween.common.helpers; - -public class InvalidAccessTokenException extends Exception{ - -} diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/InvalidAccessTokenException.kt b/app/src/main/java/moe/tlaster/openween/common/helpers/InvalidAccessTokenException.kt new file mode 100644 index 0000000..4aa6cc3 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/helpers/InvalidAccessTokenException.kt @@ -0,0 +1,3 @@ +package moe.tlaster.openween.common.helpers + +class InvalidAccessTokenException : Exception() diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/JsonCallback.java b/app/src/main/java/moe/tlaster/openween/common/helpers/JsonCallback.java deleted file mode 100644 index b84c24d..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/helpers/JsonCallback.java +++ /dev/null @@ -1,25 +0,0 @@ -package moe.tlaster.openween.common.helpers; - -import com.google.gson.Gson; -import com.zhy.http.okhttp.callback.Callback; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; - -import okhttp3.Response; - -/** - * Created by Tlaster on 2016/9/5. - */ -public abstract class JsonCallback extends Callback { - - @Override - public T parseNetworkResponse(Response response, int id) throws Exception { - String string = response.body().string(); - Type entityClass = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - if (entityClass == String.class) { - return (T) string; - } - return new Gson().fromJson(string, entityClass); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/JsonCallback.kt b/app/src/main/java/moe/tlaster/openween/common/helpers/JsonCallback.kt new file mode 100644 index 0000000..77e4695 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/helpers/JsonCallback.kt @@ -0,0 +1,25 @@ +package moe.tlaster.openween.common.helpers + +import com.google.gson.Gson +import com.zhy.http.okhttp.callback.Callback + +import java.lang.reflect.ParameterizedType +import java.lang.reflect.Type + +import okhttp3.Response + +/** + * Created by Tlaster on 2016/9/5. + */ +abstract class JsonCallback : Callback() { + + @Throws(Exception::class) + override fun parseNetworkResponse(response: Response, id: Int): T { + val string = response.body().string() + val entityClass = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] + if (entityClass === String::class.java) { + return string as T + } + return Gson().fromJson(string, entityClass) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/Reverse.java b/app/src/main/java/moe/tlaster/openween/common/helpers/Reverse.java deleted file mode 100644 index 6276ee9..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/helpers/Reverse.java +++ /dev/null @@ -1,24 +0,0 @@ -package moe.tlaster.openween.common.helpers; - -import com.annimon.stream.Stream; -import com.annimon.stream.function.UnaryOperator; - -import java.util.ArrayDeque; -import java.util.Iterator; - -/** - * Created by Asahi on 2016/9/27. - */ - -public final class Reverse implements UnaryOperator> { - - @Override - public Stream apply(Stream stream) { - final Iterator iterator = stream.iterator(); - final ArrayDeque deque = new ArrayDeque(); - while (iterator.hasNext()) { - deque.addFirst(iterator.next()); - } - return Stream.of(deque.iterator()); - } -} \ No newline at end of file diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/SettingHelper.java b/app/src/main/java/moe/tlaster/openween/common/helpers/SettingHelper.java deleted file mode 100644 index 97faed2..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/helpers/SettingHelper.java +++ /dev/null @@ -1,45 +0,0 @@ -package moe.tlaster.openween.common.helpers; - -import android.content.Context; -import android.content.SharedPreferences; -import android.text.TextUtils; - -import net.grandcentrix.tray.AppPreferences; - -/** - * Created by Asahi on 2016/9/26. - */ - -public class SettingHelper { - private final static String DELIMITER = ";"; - public final static String ACCESSTOKEN = "AccessToken"; - - public static void setSetting(final Context context, String name, String value) { - AppPreferences preferences = new AppPreferences(context); - preferences.put(name, value); - } - public static String getSetting(final Context context, String name) { - AppPreferences preferences = new AppPreferences(context); - return preferences.getString(name, null); - } - public static boolean getBooleanSetting(final Context context, String name) { - AppPreferences preferences = new AppPreferences(context); - return preferences.getBoolean(name, false); - } - public static void setListSetting(final Context context, String name, boolean isReplace, String... value) { - String saveValue = getSetting(context, name); - if (saveValue == null){ - saveValue = TextUtils.join(DELIMITER, value); - } else if (!isReplace) { - saveValue += ";" + TextUtils.join(DELIMITER, value); - } else { - saveValue = TextUtils.join(DELIMITER, value); - } - setSetting(context, name, saveValue); - } - public static String[] getListSetting(final Context context, String name) { - String value = getSetting(context, name); - if (value != null) return value.split(DELIMITER); - else return null; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/SettingHelper.kt b/app/src/main/java/moe/tlaster/openween/common/helpers/SettingHelper.kt new file mode 100644 index 0000000..ecc2996 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/helpers/SettingHelper.kt @@ -0,0 +1,51 @@ +package moe.tlaster.openween.common.helpers + +import android.content.Context +import android.content.SharedPreferences +import android.text.TextUtils + +import net.grandcentrix.tray.AppPreferences + +/** + * Created by Asahi on 2016/9/26. + */ + +object SettingHelper { + private val DELIMITER = ";" + val ACCESSTOKEN = "AccessToken" + + fun setSetting(context: Context, name: String, value: String) { + val preferences = AppPreferences(context) + preferences.put(name, value) + } + + fun getSetting(context: Context, name: String): String? { + val preferences = AppPreferences(context) + return preferences.getString(name, null) + } + + fun getBooleanSetting(context: Context, name: String): Boolean { + val preferences = AppPreferences(context) + return preferences.getBoolean(name, false) + } + + fun setListSetting(context: Context, name: String, isReplace: Boolean, vararg value: String) { + var saveValue = getSetting(context, name) + if (saveValue == null) { + saveValue = TextUtils.join(DELIMITER, value) + } else if (!isReplace) { + saveValue += ";" + TextUtils.join(DELIMITER, value) + } else { + saveValue = TextUtils.join(DELIMITER, value) + } + setSetting(context, name, saveValue!!) + } + + fun getListSetting(context: Context, name: String): Array? { + val value = getSetting(context, name) + if (value != null) + return value.split(DELIMITER.toRegex()).dropLastWhile(String::isEmpty).toTypedArray() + else + return null + } +} diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/TimeHelper.java b/app/src/main/java/moe/tlaster/openween/common/helpers/TimeHelper.java deleted file mode 100644 index fb30cd0..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/helpers/TimeHelper.java +++ /dev/null @@ -1,23 +0,0 @@ -package moe.tlaster.openween.common.helpers; - -import org.ocpsoft.prettytime.PrettyTime; - -import java.text.SimpleDateFormat; -import java.util.Locale; - -/** - * Created by Asahi on 2016/10/12. - */ - -public class TimeHelper { - private static PrettyTime mPrettyTime = new PrettyTime(new Locale("ZH_CN")); - private static SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.US); - - public static PrettyTime getmPrettyTime() { - return mPrettyTime; - } - - public static SimpleDateFormat getmSimpleDateFormat() { - return mSimpleDateFormat; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/TimeHelper.kt b/app/src/main/java/moe/tlaster/openween/common/helpers/TimeHelper.kt new file mode 100644 index 0000000..ec285d2 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/helpers/TimeHelper.kt @@ -0,0 +1,15 @@ +package moe.tlaster.openween.common.helpers + +import org.ocpsoft.prettytime.PrettyTime + +import java.text.SimpleDateFormat +import java.util.Locale + +/** + * Created by Asahi on 2016/10/12. + */ + +object TimeHelper { + val prettyTime = PrettyTime(Locale("ZH_CN")) + val simpleDateFormat = SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.US) +} diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/WeiboCardHelper.java b/app/src/main/java/moe/tlaster/openween/common/helpers/WeiboCardHelper.java deleted file mode 100644 index 5fe031f..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/helpers/WeiboCardHelper.java +++ /dev/null @@ -1,170 +0,0 @@ -package moe.tlaster.openween.common.helpers; - -import android.content.Context; -import android.content.Intent; -import android.graphics.Color; -import android.preference.PreferenceManager; -import android.text.TextUtils; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; - -import com.annimon.stream.Stream; -import com.bumptech.glide.Glide; -import com.jaeger.ninegridimageview.NineGridImageView; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import moe.tlaster.openween.R; -import moe.tlaster.openween.activity.PostWeiboActivity; -import moe.tlaster.openween.activity.UserActivity; -import moe.tlaster.openween.adapter.WeiboImageAdapter; -import moe.tlaster.openween.common.controls.WeiboTextBlock; -import moe.tlaster.openween.common.entities.PostWeiboType; -import moe.tlaster.openween.core.model.BaseModel; -import moe.tlaster.openween.core.model.comment.CommentModel; -import moe.tlaster.openween.core.model.status.MessageModel; - -/** - * Created by Asahi on 2016/10/27. - */ - -public class WeiboCardHelper { - public static void setData(View baseView, BaseModel baseModel, Context context) { - setData(baseView, baseModel, context, true); - } - public static void setData(View baseView, BaseModel baseModel, Context context, boolean isEnableRepost) { - setData(baseView, baseModel, context, isEnableRepost, Color.BLACK); - } - public static void setData(View baseView, BaseModel baseModel, Context context, boolean isEnableRepost, int textColor) { - baseView.setVisibility(View.VISIBLE); - View weiboContentContainer = baseView.findViewById(R.id.weibo_content_container); - View weiboRepostContainer = baseView.findViewById(R.id.weibo_repost_container); - View weiboRepostLinear = baseView.findViewById(R.id.weibo_repost_linear); - setWeiboContent(weiboContentContainer, baseModel, context, textColor); - if (baseModel instanceof MessageModel) { - baseView.findViewById(R.id.comment).setVisibility(View.GONE); - baseView.findViewById(R.id.weibo_action).setVisibility(View.VISIBLE); - MessageModel messageModel = (MessageModel) baseModel; - if (messageModel.getRetweetedStatus() != null && isEnableRepost) { - weiboRepostLinear.setVisibility(View.VISIBLE); - setWeiboContent(weiboRepostContainer, messageModel.getRetweetedStatus(), context); - } else { - weiboRepostLinear.setVisibility(View.GONE); - } - View weiboAction = baseView.findViewById(R.id.weibo_action); - weiboAction.setVisibility(View.VISIBLE); - ((TextView) weiboAction.findViewById(R.id.like_count)).setText(String.valueOf(messageModel.getAttitudesCount())); - ((TextView) weiboAction.findViewById(R.id.comment_count)).setText(String.valueOf(messageModel.getCommentsCount())); - ((TextView) weiboAction.findViewById(R.id.repost_count)).setText(String.valueOf(messageModel.getRepostsCount())); - weiboAction.findViewById(R.id.repost).setOnClickListener(v -> { - Intent i = new Intent(context, PostWeiboActivity.class); - i.putExtra(context.getString(R.string.post_weibo_type_name), PostWeiboType.RePost); - i.putExtra(context.getString(R.string.post_weibo_id_name), messageModel.getID()); - i.putExtra(context.getString(R.string.post_weibo_data_name), messageModel.getRetweetedStatus() == null ? "" : "//@" + messageModel.getUser().getName() + ":" + messageModel.getText()); - context.startActivity(i); - }); - weiboAction.findViewById(R.id.comment).setOnClickListener(v -> { - Intent i = new Intent(context, PostWeiboActivity.class); - i.putExtra(context.getString(R.string.post_weibo_type_name), PostWeiboType.Comment); - i.putExtra(context.getString(R.string.post_weibo_id_name), messageModel.getID()); - context.startActivity(i); - }); - } else if (baseModel instanceof CommentModel) { - baseView.findViewById(R.id.comment).setVisibility(View.VISIBLE); - baseView.findViewById(R.id.weibo_action).setVisibility(View.GONE); - CommentModel commentModel = (CommentModel) baseModel; - if (isEnableRepost) { - weiboRepostLinear.setVisibility(View.VISIBLE); - setWeiboContent(baseView.findViewById(R.id.weibo_repost_container), commentModel.getStatus(), false, context); - } else { - weiboRepostLinear.setVisibility(View.GONE); - } - baseView.findViewById(R.id.comment).setOnClickListener(getReplyCommentListener(commentModel, context)); - } - } - - public static boolean shouldBlock(Context context, BaseModel baseModel) { - String blockText = PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.block_text_key), null); - String blockUserid = PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.block_userid_key), null); - if (TextUtils.isEmpty(blockText) && TextUtils.isEmpty(blockUserid)) return false; - Set blockTextList = new HashSet<>(Arrays.asList(blockText != null ? blockText.split(",") : new String[0])); - Set blockUserList = new HashSet<>(Arrays.asList(blockUserid != null ? blockUserid.split(",") : new String[0])); - if (baseModel instanceof MessageModel) { - MessageModel model = (MessageModel) baseModel; - return blockUserList.contains(String.valueOf(model.getUser().getID())) || - (model.getRetweetedStatus() != null && model.getRetweetedStatus().getUser() != null && blockUserList.contains(String.valueOf(model.getRetweetedStatus().getUser().getID()))) || - Stream.of(blockTextList).anyMatch(item -> !TextUtils.isEmpty(item) && model.getText().contains(item)) || - (model.getRetweetedStatus() != null && model.getRetweetedStatus().getText() != null && Stream.of(blockTextList).anyMatch(item -> !TextUtils.isEmpty(item) && model.getRetweetedStatus().getText().contains(item))); - } else if (baseModel instanceof CommentModel) { - CommentModel model = (CommentModel) baseModel; - return blockUserList.contains(String.valueOf(model.getUser().getID())) || - (model.getReplyComment() != null && model.getReplyComment().getUser() != null && blockUserList.contains(String.valueOf(model.getReplyComment().getUser().getID()))) || - Stream.of(blockTextList).anyMatch(item -> !TextUtils.isEmpty(item) && model.getText().contains(item)) || - (model.getReplyComment() != null && model.getReplyComment().getText() != null && Stream.of(blockTextList).anyMatch(item -> !TextUtils.isEmpty(item) && model.getReplyComment().getText().contains(item))); - } - return false; - } - - private static View.OnClickListener getReplyCommentListener(CommentModel commentModel, Context context){ - return v -> { - Intent i = new Intent(context, PostWeiboActivity.class); - i.putExtra(context.getString(R.string.post_weibo_type_name), PostWeiboType.ReplyComment); - i.putExtra(context.getString(R.string.post_weibo_data_name), "回复@" + commentModel.getUser().getName() + ":"); - i.putExtra(context.getString(R.string.post_weibo_id_name), commentModel.getStatus().getID()); - i.putExtra(context.getString(R.string.post_weibo_cid_name), commentModel.getID()); - context.startActivity(i); - }; - } - - - private static void setWeiboContent(View view, BaseModel item, Context context) { - setWeiboContent(view, item, true, context); - } - private static void setWeiboContent(View view, BaseModel item, Context context, int textColor) { - setWeiboContent(view, item, true, context, textColor); - } - private static void setWeiboContent(View view, BaseModel item, boolean enableImage, Context context) { - setWeiboContent(view, item, enableImage, context, Color.BLACK); - } - private static void setWeiboContent(View view, BaseModel item, boolean enableImage, Context context, int textColor) { - View userHeader = view.findViewById(R.id.user_header); - TextView userName = (TextView) userHeader.findViewById(R.id.user_name); - TextView time = (TextView) userHeader.findViewById(R.id.user_sub_text); - WeiboTextBlock content = (WeiboTextBlock) view.findViewById(R.id.weibo_content); - userName.setTextColor(textColor); - content.setTextColor(textColor); - if (item.getUser() != null) { - Glide.with(context).load(item.getUser().getAvatarLarge()).into((ImageView) userHeader.findViewById(R.id.user_img)); - userName.setText(item.getUser().getScreenName()); - userName.setOnClickListener(v -> goUserActivity(item.getUser().getScreenName(), context)); - userHeader.setOnClickListener(v -> goUserActivity(item.getUser().getScreenName(), context)); - } - time.setText(item.getCreatedAtDiffForHuman()); - content.setText(item.getText()); - content.setUserClicked(data -> goUserActivity(data, context)); - NineGridImageView nineGridImageView = (NineGridImageView) view.findViewById(R.id.weibo_img); - if (item instanceof MessageModel) { - if (enableImage) { - nineGridImageView.setVisibility(View.VISIBLE); - MessageModel model = (MessageModel) item; - nineGridImageView.setAdapter(new WeiboImageAdapter()); - nineGridImageView.setImagesData(model.getPicUrls()); - } else { - nineGridImageView.setVisibility(View.GONE); - } - } else if (item instanceof CommentModel) { - CommentModel commentModel = (CommentModel) item; - nineGridImageView.setVisibility(View.GONE); - content.setOnClickListener(getReplyCommentListener(commentModel, context)); - } - } - public static void goUserActivity(String userName, Context context){ - Intent intent = new Intent(context, UserActivity.class); - intent.putExtra(context.getString(R.string.user_page_username_name), userName); - context.startActivity(intent); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/common/helpers/WeiboCardHelper.kt b/app/src/main/java/moe/tlaster/openween/common/helpers/WeiboCardHelper.kt new file mode 100644 index 0000000..7eefcca --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/helpers/WeiboCardHelper.kt @@ -0,0 +1,150 @@ +package moe.tlaster.openween.common.helpers + +import android.content.Context +import android.content.Intent +import android.graphics.Color +import android.preference.PreferenceManager +import android.text.TextUtils +import android.view.View +import android.widget.ImageView +import android.widget.TextView + + +import com.bumptech.glide.Glide +import com.jaeger.ninegridimageview.NineGridImageView + +import java.util.Arrays +import java.util.HashSet + +import moe.tlaster.openween.R +import moe.tlaster.openween.activity.PostWeiboActivity +import moe.tlaster.openween.activity.UserActivity +import moe.tlaster.openween.adapter.WeiboImageAdapter +import moe.tlaster.openween.common.controls.WeiboTextBlock +import moe.tlaster.openween.common.entities.PostWeiboType +import moe.tlaster.openween.core.model.BaseModel +import moe.tlaster.openween.core.model.comment.CommentModel +import moe.tlaster.openween.core.model.status.MessageModel + +/** + * Created by Asahi on 2016/10/27. + */ + +internal object WeiboCardHelper { + @JvmOverloads fun setData(baseView: View, baseModel: BaseModel, context: Context, isEnableRepost: Boolean = true, textColor: Int = Color.BLACK) { + baseView.visibility = View.VISIBLE + val weiboContentContainer = baseView.findViewById(R.id.weibo_content_container) + val weiboRepostContainer = baseView.findViewById(R.id.weibo_repost_container) + val weiboRepostLinear = baseView.findViewById(R.id.weibo_repost_linear) + setWeiboContent(weiboContentContainer, baseModel, context, textColor) + if (baseModel is MessageModel) { + baseView.findViewById(R.id.comment).visibility = View.GONE + baseView.findViewById(R.id.weibo_action).visibility = View.VISIBLE + if (baseModel.retweetedStatus != null && isEnableRepost) { + weiboRepostLinear.visibility = View.VISIBLE + setWeiboContent(weiboRepostContainer, baseModel.retweetedStatus as MessageModel, context) + } else { + weiboRepostLinear.visibility = View.GONE + } + val weiboAction = baseView.findViewById(R.id.weibo_action) + weiboAction.visibility = View.VISIBLE + (weiboAction.findViewById(R.id.like_count) as TextView).text = baseModel.attitudesCount.toString() + (weiboAction.findViewById(R.id.comment_count) as TextView).text = baseModel.commentsCount.toString() + (weiboAction.findViewById(R.id.repost_count) as TextView).text = baseModel.repostsCount.toString() + weiboAction.findViewById(R.id.repost).setOnClickListener { v -> + val i = Intent(context, PostWeiboActivity::class.java) + i.putExtra(context.getString(R.string.post_weibo_type_name), PostWeiboType.RePost) + i.putExtra(context.getString(R.string.post_weibo_id_name), baseModel.id) + i.putExtra(context.getString(R.string.post_weibo_data_name), if (baseModel.retweetedStatus == null) "" else "//@" + baseModel.user!!.name + ":" + baseModel.text) + context.startActivity(i) + } + weiboAction.findViewById(R.id.comment).setOnClickListener { v -> + val i = Intent(context, PostWeiboActivity::class.java) + i.putExtra(context.getString(R.string.post_weibo_type_name), PostWeiboType.Comment) + i.putExtra(context.getString(R.string.post_weibo_id_name), baseModel.id) + context.startActivity(i) + } + } else if (baseModel is CommentModel) { + baseView.findViewById(R.id.comment).visibility = View.VISIBLE + baseView.findViewById(R.id.weibo_action).visibility = View.GONE + if (isEnableRepost) { + weiboRepostLinear.visibility = View.VISIBLE + setWeiboContent(baseView.findViewById(R.id.weibo_repost_container), baseModel.status as MessageModel, false, context) + } else { + weiboRepostLinear.visibility = View.GONE + } + baseView.findViewById(R.id.comment).setOnClickListener(getReplyCommentListener(baseModel, context)) + } + } + + fun shouldBlock(context: Context, baseModel: BaseModel): Boolean { + val blockText = PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.block_text_key), null) + val blockUserid = PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.block_userid_key), null) + if (TextUtils.isEmpty(blockText) && TextUtils.isEmpty(blockUserid)) return false + val blockTextList = HashSet(Arrays.asList(*blockText?.split(",".toRegex())?.dropLastWhile { it.isEmpty() }?.toTypedArray() ?: arrayOfNulls(0))) + val blockUserList = HashSet(Arrays.asList(*blockUserid?.split(",".toRegex())?.dropLastWhile { it.isEmpty() }?.toTypedArray() ?: arrayOfNulls(0))) + if (baseModel is MessageModel) { + return blockUserList.contains(baseModel.user!!.id.toString()) || baseModel.retweetedStatus != null && baseModel.retweetedStatus!!.user != null && blockUserList.contains(baseModel.retweetedStatus!!.user!!.id.toString()) || blockTextList.any { item -> !TextUtils.isEmpty(item) && baseModel.text.contains(item) } || baseModel.retweetedStatus != null && blockTextList.any { item -> !TextUtils.isEmpty(item) && baseModel.retweetedStatus!!.text.contains(item) } + } else if (baseModel is CommentModel) { + return blockUserList.contains(baseModel.user?.id.toString()) || baseModel.replyComment != null && baseModel.replyComment!!.user != null && blockUserList.contains(baseModel.replyComment!!.user!!.id.toString()) || blockTextList.any { item -> !TextUtils.isEmpty(item) && baseModel.text.contains(item) } || baseModel.replyComment != null && blockTextList.any { item -> !TextUtils.isEmpty(item) && baseModel.replyComment!!.text.contains(item) } + } + return false + } + + private fun getReplyCommentListener(commentModel: CommentModel, context: Context): View.OnClickListener { + return View.OnClickListener { v -> + val i = Intent(context, PostWeiboActivity::class.java) + i.putExtra(context.getString(R.string.post_weibo_type_name), PostWeiboType.ReplyComment) + i.putExtra(context.getString(R.string.post_weibo_data_name), "回复@" + commentModel.user!!.name + ":") + i.putExtra(context.getString(R.string.post_weibo_id_name), commentModel.status!!.id) + i.putExtra(context.getString(R.string.post_weibo_cid_name), commentModel.id) + context.startActivity(i) + } + } + + + private fun setWeiboContent(view: View, item: BaseModel, context: Context) { + setWeiboContent(view, item, true, context) + } + + private fun setWeiboContent(view: View, item: BaseModel, context: Context, textColor: Int) { + setWeiboContent(view, item, true, context, textColor) + } + + private fun setWeiboContent(view: View, item: BaseModel, enableImage: Boolean, context: Context, textColor: Int = Color.BLACK) { + val userHeader = view.findViewById(R.id.user_header) + val userName = userHeader.findViewById(R.id.user_name) as TextView + val time = userHeader.findViewById(R.id.user_sub_text) as TextView + val content = view.findViewById(R.id.weibo_content) as WeiboTextBlock + userName.setTextColor(textColor) + content.setTextColor(textColor) + if (item.user != null) { + Glide.with(context).load(item.user!!.avatarLarge).into(userHeader.findViewById(R.id.user_img) as ImageView) + userName.text = item.user!!.screenName + userName.setOnClickListener { v -> goUserActivity(item.user!!.screenName!!, context) } + userHeader.setOnClickListener { v -> goUserActivity(item.user!!.screenName!!, context) } + } + time.text = item.createdAtDiffForHuman + content.text = item.text + content.userClicked += { data -> goUserActivity(data, context) } + val nineGridImageView = view.findViewById(R.id.weibo_img) as NineGridImageView<*> + if (item is MessageModel) { + if (enableImage) { + nineGridImageView.visibility = View.VISIBLE + nineGridImageView.setAdapter(WeiboImageAdapter()) + nineGridImageView.setImagesData(item.picUrls) + } else { + nineGridImageView.setVisibility(View.GONE) + } + } else if (item is CommentModel) { + nineGridImageView.visibility = View.GONE + content.setOnClickListener(getReplyCommentListener(item, context)) + } + } + + fun goUserActivity(userName: String, context: Context) { + val intent = Intent(context, UserActivity::class.java) + intent.putExtra(context.getString(R.string.user_page_username_name), userName) + context.startActivity(intent) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/common/service/NotificationService.java b/app/src/main/java/moe/tlaster/openween/common/service/NotificationService.java deleted file mode 100644 index 657e78c..0000000 --- a/app/src/main/java/moe/tlaster/openween/common/service/NotificationService.java +++ /dev/null @@ -1,106 +0,0 @@ -package moe.tlaster.openween.common.service; - -import android.app.IntentService; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.app.job.JobParameters; -import android.app.job.JobService; -import android.content.Context; -import android.content.Intent; -import android.graphics.BitmapFactory; -import android.preference.PreferenceManager; -import android.support.v4.app.NotificationCompat; -import android.support.v4.app.TaskStackBuilder; -import android.text.TextUtils; -import android.util.Log; - -import com.google.gson.Gson; - -import moe.tlaster.openween.R; -import moe.tlaster.openween.activity.MainActivity; -import moe.tlaster.openween.common.helpers.DeviceHelper; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.common.helpers.SettingHelper; -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.UnreadModel; -import okhttp3.Call; - -/** - * Created by Asahi on 2016/11/9. - */ - -public class NotificationService extends IntentService { - public NotificationService() { - super(NotificationService.class.getName()); - } - - @Override - public void onCreate() { - super.onCreate(); - } - - @Override - protected void onHandleIntent(Intent intent) { - Log.i(NotificationService.class.getName(), "onHandleIntent"); - Context context = getApplicationContext(); - if (!DeviceHelper.checkWifiOnAndConnected(context) || !PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.enable_notification_name), true)) return; - try { - String accessToken = SettingHelper.getListSetting(context, SettingHelper.ACCESSTOKEN)[0]; - HttpHelper.getAsync(Constants.REMIND_UNREAD_COUNT, accessToken, null, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - - @Override - public void onResponse(UnreadModel response, int id) { - sendNotification(response); - } - }); - } catch (Exception e) { - } - } - - private void sendNotification(UnreadModel unread) { - Context context = getApplicationContext(); - String prevString = SettingHelper.getSetting(context, getString(R.string.unread_item_name)); - UnreadModel prevUnread; - if (prevString == null) - prevUnread= new UnreadModel(); - else - prevUnread = new Gson().fromJson(prevString, UnreadModel.class); - String notifyText = ""; - if (unread.getMentionStatus() > 0 && unread.getMentionStatus() != prevUnread.getMentionStatus() && PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.is_mention_notify_name), true)) { - notifyText += String.valueOf(unread.getMentionStatus()) + " 条新@ "; - } - if (unread.getCmt() > 0 && unread.getCmt() != prevUnread.getCmt() && PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.is_comment_notify_name), true)) { - notifyText += String.valueOf(unread.getCmt()) + " 条新评论 "; - } - if (unread.getMentionCmt() > 0 && unread.getMentionCmt() != prevUnread.getMentionCmt() && PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.is_mention_notify_name), true)) { - notifyText += String.valueOf(unread.getMentionCmt()) + " 条新提及的评论 "; - } - if (unread.getFollower() > 0 && unread.getFollower() != prevUnread.getFollower() && PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.is_follower_notify_name), true)) { - notifyText += String.valueOf(unread.getFollower()) + " 个新粉丝 "; - } - if (unread.getDm() > 0 && unread.getDm() != prevUnread.getDm() && PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.is_message_notify_name), true)) { - notifyText += String.valueOf(unread.getDm()) + " 条新私信 "; - } - if (!TextUtils.isEmpty(notifyText)) { - Intent notificationIntent = new Intent(context, MainActivity.class); - notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); - PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); - NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - NotificationCompat.Builder mBuilder = - new NotificationCompat.Builder(context) - .setSmallIcon(R.drawable.ic_notification_icon) - .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) - .setContentTitle(getString(R.string.app_name)) - .setContentIntent(pendingIntent) - .setAutoCancel(true) - .setContentText(notifyText); - notificationManager.notify(1, mBuilder.build()); - } - SettingHelper.setSetting(context, getString(R.string.unread_item_name), new Gson().toJson(unread)); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/common/service/NotificationService.kt b/app/src/main/java/moe/tlaster/openween/common/service/NotificationService.kt new file mode 100644 index 0000000..b2763bb --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/common/service/NotificationService.kt @@ -0,0 +1,99 @@ +package moe.tlaster.openween.common.service + +import android.app.IntentService +import android.app.NotificationManager +import android.app.PendingIntent +import android.app.job.JobParameters +import android.app.job.JobService +import android.content.Context +import android.content.Intent +import android.graphics.BitmapFactory +import android.preference.PreferenceManager +import android.support.v4.app.NotificationCompat +import android.support.v4.app.TaskStackBuilder +import android.text.TextUtils +import android.util.Log + +import com.google.gson.Gson + +import moe.tlaster.openween.R +import moe.tlaster.openween.activity.MainActivity +import moe.tlaster.openween.common.helpers.DeviceHelper +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.common.helpers.SettingHelper +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.UnreadModel +import okhttp3.Call + +/** + * Created by Asahi on 2016/11/9. + */ + +class NotificationService : IntentService(NotificationService::class.java.name) { + + override fun onCreate() { + super.onCreate() + } + + override fun onHandleIntent(intent: Intent?) { + Log.i(NotificationService::class.java.name, "onHandleIntent") + val context = applicationContext + if (!DeviceHelper.checkWifiOnAndConnected(context) || !PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.enable_notification_name), true)) return + try { + val accessToken = SettingHelper.getListSetting(context, SettingHelper.ACCESSTOKEN)!![0] + HttpHelper.getAsync(Constants.REMIND_UNREAD_COUNT, accessToken, null, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + + } + + override fun onResponse(response: UnreadModel, id: Int) { + sendNotification(response) + } + }) + } catch (e: Exception) { + } + + } + + private fun sendNotification(unread: UnreadModel) { + val context = applicationContext + val prevString = SettingHelper.getSetting(context, getString(R.string.unread_item_name)) + val prevUnread: UnreadModel + if (prevString == null) + prevUnread = UnreadModel() + else + prevUnread = Gson().fromJson(prevString, UnreadModel::class.java) + var notifyText = "" + if (unread.mentionStatus > 0 && unread.mentionStatus != prevUnread.mentionStatus && PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.is_mention_notify_name), true)) { + notifyText += unread.mentionStatus.toString() + " 条新@ " + } + if (unread.cmt > 0 && unread.cmt != prevUnread.cmt && PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.is_comment_notify_name), true)) { + notifyText += unread.cmt.toString() + " 条新评论 " + } + if (unread.mentionCmt > 0 && unread.mentionCmt != prevUnread.mentionCmt && PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.is_mention_notify_name), true)) { + notifyText += unread.mentionCmt.toString() + " 条新提及的评论 " + } + if (unread.follower > 0 && unread.follower != prevUnread.follower && PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.is_follower_notify_name), true)) { + notifyText += unread.follower.toString() + " 个新粉丝 " + } + if (unread.dm > 0 && unread.dm != prevUnread.dm && PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.is_message_notify_name), true)) { + notifyText += unread.dm.toString() + " 条新私信 " + } + if (!TextUtils.isEmpty(notifyText)) { + val notificationIntent = Intent(context, MainActivity::class.java) + notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP) + val pendingIntent = PendingIntent.getActivity(context, 1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT) + val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val mBuilder = NotificationCompat.Builder(context) + .setSmallIcon(R.drawable.ic_notification_icon) + .setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher)) + .setContentTitle(getString(R.string.app_name)) + .setContentIntent(pendingIntent) + .setAutoCancel(true) + .setContentText(notifyText) + notificationManager.notify(1, mBuilder.build()) + } + SettingHelper.setSetting(context, getString(R.string.unread_item_name), Gson().toJson(unread)) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/Constants.java b/app/src/main/java/moe/tlaster/openween/core/api/Constants.java deleted file mode 100644 index 2fea8bf..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/Constants.java +++ /dev/null @@ -1,117 +0,0 @@ -package moe.tlaster.openween.core.api; - -/** - * Created by Tlaster on 2016/9/3. - */ -public class Constants { - - public static final String SINA_BASE_URL = "https://api.weibo.com/2/"; - - // Login - public static final String OAUTH2_ACCESS_AUTHORIZE = "https://open.weibo.cn/oauth2/authorize"; - - public static final String OAUTH2_ACCESS_TOKEN = SINA_BASE_URL + "oauth2/access_token"; - - // User / Account - public static final String USER_SHOW = SINA_BASE_URL + "users/show.json";//User.GetUser - public static final String USER_COUNTS = SINA_BASE_URL + "users/counts.json";//User.GetUserInfo - public static final String USER_DOMAIN_SHOW = SINA_BASE_URL + "users/domain_show.json";//User.GetUserByDomain - public static final String RATE_LIMIT_STATUS = SINA_BASE_URL + "account/rate_limit_status.json";//Account.GetLimitStatus - public static final String GET_UID = SINA_BASE_URL + "account/get_uid.json";//Account.GetUid - public static final String GET_USER_MAIL = SINA_BASE_URL + "account/profile/email.json";//Account.GetMail - - // Statuses - public static final String PUBLIC_TIMELINE = SINA_BASE_URL + "statuses/public_timeline";//Public.GetPublicTimeline - public static final String HOME_TIMELINE = SINA_BASE_URL + "statuses/home_timeline.json";//Home.GetTimeline - public static final String USER_TIMELINE = SINA_BASE_URL + "statuses/user_timeline.json";//UserTimeline.GetUserTimeline - public static final String BILATERAL_TIMELINE = SINA_BASE_URL + "statuses/bilateral_timeline.json";//Bilateral.GetBilateral - public static final String TIMELINE_BATCH = SINA_BASE_URL + "statuses/timeline_batch.json";//Timeline.GetTimelineBatch - public static final String MENTIONS = SINA_BASE_URL + "statuses/mentions.json";//Mentions.GetMentions - public static final String MENTIONS_SHIELD = SINA_BASE_URL + "statuses/mentions/shield.json";//Mentions.Shield - public static final String REPOST_TIMELINE = SINA_BASE_URL + "statuses/repost_timeline.json";//Repost.GetRepost - public static final String UPDATE = SINA_BASE_URL + "statuses/update.json";//PostWeibo.Post - public static final String UPLOAD = SINA_BASE_URL + "statuses/upload.json";//PostWeibo.PostWithPic - public static final String REPOST = SINA_BASE_URL + "statuses/repost.json";//PostWeibo.RePost - public static final String DESTROY = SINA_BASE_URL + "statuses/destroy.json";//PostWeibo.DeletePost - public static final String UPLOAD_PIC = SINA_BASE_URL + "statuses/upload_pic.json";//PostWeibo.UploadPicture - public static final String UPLOAD_URL_TEXT = SINA_BASE_URL + "statuses/upload_url_text.json";//PostWeibo.PostWithMultiPics - public static final String QUERY_ID = SINA_BASE_URL + "statuses/queryid.json";//Query.QueryID - public static final String QUERY_MID = SINA_BASE_URL + "statuses/querymid.json";//Query.QueryMID - public static final String SHOW = SINA_BASE_URL + "statuses/show.json";//Query.GetStatus - public static final String SHOW_BATCH = SINA_BASE_URL + "statuses/show_batch.json";//Query.GetStatus - public static final String EMOTIONS = SINA_BASE_URL + "emotions.json";//Emotions.GetEmotions - public static final String FILTER_CREATE = SINA_BASE_URL + "statuses/filter/create.json";//Filter.Create - - // Comments - public static final String COMMENTS_TIMELINE = SINA_BASE_URL + "comments/timeline.json";//Comments.GetComment,Comment.GetCommentSince - public static final String COMMENTS_MENTIONS = SINA_BASE_URL + "comments/mentions.json";//Comments.GetCommentMentions - public static final String COMMENTS_TO_ME = SINA_BASE_URL + "comments/to_me.json";//Comments.GetCommentToMe - public static final String COMMENTS_BY_ME = SINA_BASE_URL + "comments/by_me.json";//Comments.GetCommentByMe - public static final String COMMENTS_SHOW = SINA_BASE_URL + "comments/show.json";//Comments.GetCommentStatus - public static final String COMMENTS_CREATE = SINA_BASE_URL + "comments/create.json";//Comments.PostComment - public static final String COMMENTS_REPLY = SINA_BASE_URL + "comments/reply.json";//Comments.Reply - public static final String COMMENTS_DESTROY = SINA_BASE_URL + "comments/destroy.json";//Comments.Delete - public static final String COMMENTS_BATCH = SINA_BASE_URL + "comments/show_batch.json";//Comments.Batch - public static final String COMMENTS_DESTROY_BATCH = SINA_BASE_URL + "comments/destroy_batch.json";//Comments.DeleteBatch - - // Favorites - public static final String FAVORITES_CREATE = SINA_BASE_URL + "favorites/create.json";//Favorites.AddFavor - public static final String FAVORITES_DESTROY = SINA_BASE_URL + "favorites/destroy.json";//Favorites.RemoveFavor - public static final String FAVORITES_LIST = SINA_BASE_URL + "favorites.json";//Favorites.GetFavorList - public static final String FAVORITES_SHOW = SINA_BASE_URL + "favorites/show.json";//Favorites.GetFavor - public static final String FAVORITES_LIST_BY_TAG = SINA_BASE_URL + "favorites/by_tags.json";//Favorites.GetFavorListByTag - public static final String FAVORITES_TAGS = SINA_BASE_URL + "favorites/tags.json";//Favorites.GetTags - public static final String FAVORITES_DESTROY_BATCH = SINA_BASE_URL + "favorites/destroy_batch.json";//Favorites.RemoveFavors - public static final String FAVORITES_TAGS_UPDATE = SINA_BASE_URL + "avorites/tags/update.json";//Favorites.UpdateTags - - // Blocks - public static final String BLOCKS_LIST = SINA_BASE_URL + "blocks/blocking.json";//Blocks.GetBlocksList - public static final String BLOCKS_CREATE = SINA_BASE_URL + "blocks/create.json";//Blocks.AddBlock - public static final String BLOCKS_DESTROY = SINA_BASE_URL + "blocks/destroy.json";//Blocks.RemoveBlock - public static final String BLOCKS_EXISTS = SINA_BASE_URL + "blocks/exists.json";//Blocks.IsBlocked - - // Search - public static final String SEARCH_TOPICS = SINA_BASE_URL + "search/topics.json";//Topics.GetSearchTopics - public static final String SEARCH_STATUSES = SINA_BASE_URL + "search/statuses.json";//Search.SearchStatus - public static final String SEARCH_USERS = SINA_BASE_URL + "search/users.json";//Search.SearchUsers - public static final String SEARCH_SUGGESTIONS_AT_USERS = SINA_BASE_URL + "search/suggestions/at_users.json";//Search.SuggestAtUser - - // Friendships - public static final String FRIENDSHIPS_FRIENDS = SINA_BASE_URL + "friendships/friends.json";//Friends.GetFriends - public static final String FRIENDSHIPS_FOLLOWERS = SINA_BASE_URL + "friendships/followers.json";//Friends.GetFollowers - public static final String FRIENDSHIPS_CREATE = SINA_BASE_URL + "friendships/create.json";//Friends.Follow - public static final String FRIENDSHIPS_DESTROY = SINA_BASE_URL + "friendships/destroy.json";//Friends.UnFollow - public static final String FRIENDSHIPS_FRIENDS_IN_COMMON = SINA_BASE_URL + "friendships/friends/in_common.json";//Friends.GetFriendsInCommon - public static final String FRIENDSHIPS_FRIENDS_BILATERAL = SINA_BASE_URL + "friendships/friends/bilateral.json";//Friends.GetBliateral - public static final String FRIENDSHIPS_FOLLOWERS_ACTIVE = SINA_BASE_URL + "friendships/followers/active.json";//Friends.GetActiveFollowers - public static final String FRIENDSHIPS_FRIENDS_CHAIN = SINA_BASE_URL + "friendships/friends_chain/followers.json";//Friends.GetFriendsChain - public static final String FRIENDSHIPS_GROUPS = SINA_BASE_URL + "friendships/groups.json";//Groups.GetGroups - public static final String FRIENDSHIPS_GROUPS_IS_MEMBER = SINA_BASE_URL + "friendships/groups/is_member.json";//Groups.IsMember - public static final String FRIENDSHIPS_GROUPS_TIMELINE = SINA_BASE_URL + "friendships/groups/timeline.json";//Groups.GetGroupTimeline - public static final String FRIENDSHIPS_GROUPS_CREATE = SINA_BASE_URL + "friendships/groups/create.json";//Groups.CreateGroup - public static final String FRIENDSHIPS_GROUPS_DESTROY = SINA_BASE_URL + "friendships/groups/destroy.json";//Groups.DeleteGroup - public static final String FRIENDSHIPS_GROUPS_MEMBERS_ADD = SINA_BASE_URL + "friendships/groups/members/add.json";//Groups.AddToGroup - public static final String FRIENDSHIPS_GROUPS_MEMBERS_DESTROY = SINA_BASE_URL + "friendships/groups/members/destroy.json";//Groups.RemoveFromGroup - - // Direct Message - public static final String DIRECT_MESSAGES = SINA_BASE_URL + "direct_messages.json";//DirectMessages.GetDirectMessages - public static final String DIRECT_MESSAGES_USER_LIST = SINA_BASE_URL + "direct_messages/user_list.json";//DirectMessage.GetUserList - public static final String DIRECT_MESSAGES_CONVERSATION = SINA_BASE_URL + "direct_messages/conversation.json";//DirectMessage.GetConversation - public static final String DIRECT_MESSAGES_SEND = SINA_BASE_URL + "direct_messages/new.json";//DirectMessage.Send - public static final String DIRECT_MESSAGES_THUMB_PIC = "https://upload.api.weibo.com/2/mss/msget_thumbnail?fid=%d&access_token=%s&high=%d&width=%d";//TODO: replace %d and %s - public static final String DIRECT_MESSAGES_ORIG_PIC = "https://upload.api.weibo.com/2/mss/msget?fid=%d&access_token=%s";//TODO: replace %d and %s - public static final String DIRECT_MESSAGES_UPLOAD_PIC = "https://upload.api.weibo.com/2/mss/upload.json?tuid=";//DirectMessage.SendPicture - - // Remind - public static final String REMIND_UNREAD_COUNT = "https://rm.api.weibo.com/2/remind/unread_count.json";//Remind.GetUnRead - public static final String REMIND_UNREAD_SET_COUNT = "https://rm.api.weibo.com/2/remind/set_count.json";//Remind.ClearUnRead - - // Attitude - public static final String ATTITUDE_CREATE = SINA_BASE_URL + "attitudes/create.json";//Attitudes.Like - public static final String ATTITUDE_DESTROY = SINA_BASE_URL + "attitudes/destroy.json";//Attitudes.UnLike - - // Short Url - public static final String SHORT_URL_SHORTEN = SINA_BASE_URL + "short_url/shorten.json";//ShortUrl.Shorten - public static final String SHORT_URL_EXPAND = SINA_BASE_URL + "short_url/expand.json";//ShortUrl.Expand - public static final String SHORT_URL_INFO = SINA_BASE_URL + "short_url/info.json";//ShortUrl.Info -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/Constants.kt b/app/src/main/java/moe/tlaster/openween/core/api/Constants.kt new file mode 100644 index 0000000..46ff63c --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/Constants.kt @@ -0,0 +1,117 @@ +package moe.tlaster.openween.core.api + +/** + * Created by Tlaster on 2016/9/3. + */ +object Constants { + + val SINA_BASE_URL = "https://api.weibo.com/2/" + + // Login + val OAUTH2_ACCESS_AUTHORIZE = "https://open.weibo.cn/oauth2/authorize" + + val OAUTH2_ACCESS_TOKEN = SINA_BASE_URL + "oauth2/access_token" + + // User / Account + val USER_SHOW = SINA_BASE_URL + "users/show.json"//User.GetUser + val USER_COUNTS = SINA_BASE_URL + "users/counts.json"//User.GetUserInfo + val USER_DOMAIN_SHOW = SINA_BASE_URL + "users/domain_show.json"//User.GetUserByDomain + val RATE_LIMIT_STATUS = SINA_BASE_URL + "account/rate_limit_status.json"//Account.GetLimitStatus + val GET_UID = SINA_BASE_URL + "account/get_uid.json"//Account.GetUid + val GET_USER_MAIL = SINA_BASE_URL + "account/profile/email.json"//Account.GetMail + + // Statuses + val PUBLIC_TIMELINE = SINA_BASE_URL + "statuses/public_timeline"//Public.GetPublicTimeline + val HOME_TIMELINE = SINA_BASE_URL + "statuses/home_timeline.json"//Home.GetTimeline + val USER_TIMELINE = SINA_BASE_URL + "statuses/user_timeline.json"//UserTimeline.GetUserTimeline + val BILATERAL_TIMELINE = SINA_BASE_URL + "statuses/bilateral_timeline.json"//Bilateral.GetBilateral + val TIMELINE_BATCH = SINA_BASE_URL + "statuses/timeline_batch.json"//Timeline.GetTimelineBatch + val MENTIONS = SINA_BASE_URL + "statuses/mentions.json"//Mentions.GetMentions + val MENTIONS_SHIELD = SINA_BASE_URL + "statuses/mentions/shield.json"//Mentions.Shield + val REPOST_TIMELINE = SINA_BASE_URL + "statuses/repost_timeline.json"//Repost.GetRepost + val UPDATE = SINA_BASE_URL + "statuses/update.json"//PostWeibo.Post + val UPLOAD = SINA_BASE_URL + "statuses/upload.json"//PostWeibo.PostWithPic + val REPOST = SINA_BASE_URL + "statuses/repost.json"//PostWeibo.RePost + val DESTROY = SINA_BASE_URL + "statuses/destroy.json"//PostWeibo.DeletePost + val UPLOAD_PIC = SINA_BASE_URL + "statuses/upload_pic.json"//PostWeibo.UploadPicture + val UPLOAD_URL_TEXT = SINA_BASE_URL + "statuses/upload_url_text.json"//PostWeibo.PostWithMultiPics + val QUERY_ID = SINA_BASE_URL + "statuses/queryid.json"//Query.QueryID + val QUERY_MID = SINA_BASE_URL + "statuses/querymid.json"//Query.QueryMID + val SHOW = SINA_BASE_URL + "statuses/show.json"//Query.GetStatus + val SHOW_BATCH = SINA_BASE_URL + "statuses/show_batch.json"//Query.GetStatus + val EMOTIONS = SINA_BASE_URL + "emotions.json"//Emotions.GetEmotions + val FILTER_CREATE = SINA_BASE_URL + "statuses/filter/create.json"//Filter.Create + + // Comments + val COMMENTS_TIMELINE = SINA_BASE_URL + "comments/timeline.json"//Comments.GetComment,Comment.GetCommentSince + val COMMENTS_MENTIONS = SINA_BASE_URL + "comments/mentions.json"//Comments.GetCommentMentions + val COMMENTS_TO_ME = SINA_BASE_URL + "comments/to_me.json"//Comments.GetCommentToMe + val COMMENTS_BY_ME = SINA_BASE_URL + "comments/by_me.json"//Comments.GetCommentByMe + val COMMENTS_SHOW = SINA_BASE_URL + "comments/show.json"//Comments.GetCommentStatus + val COMMENTS_CREATE = SINA_BASE_URL + "comments/create.json"//Comments.PostComment + val COMMENTS_REPLY = SINA_BASE_URL + "comments/reply.json"//Comments.Reply + val COMMENTS_DESTROY = SINA_BASE_URL + "comments/destroy.json"//Comments.Delete + val COMMENTS_BATCH = SINA_BASE_URL + "comments/show_batch.json"//Comments.Batch + val COMMENTS_DESTROY_BATCH = SINA_BASE_URL + "comments/destroy_batch.json"//Comments.DeleteBatch + + // Favorites + val FAVORITES_CREATE = SINA_BASE_URL + "favorites/create.json"//Favorites.AddFavor + val FAVORITES_DESTROY = SINA_BASE_URL + "favorites/destroy.json"//Favorites.RemoveFavor + val FAVORITES_LIST = SINA_BASE_URL + "favorites.json"//Favorites.GetFavorList + val FAVORITES_SHOW = SINA_BASE_URL + "favorites/show.json"//Favorites.GetFavor + val FAVORITES_LIST_BY_TAG = SINA_BASE_URL + "favorites/by_tags.json"//Favorites.GetFavorListByTag + val FAVORITES_TAGS = SINA_BASE_URL + "favorites/tags.json"//Favorites.GetTags + val FAVORITES_DESTROY_BATCH = SINA_BASE_URL + "favorites/destroy_batch.json"//Favorites.RemoveFavors + val FAVORITES_TAGS_UPDATE = SINA_BASE_URL + "avorites/tags/update.json"//Favorites.UpdateTags + + // Blocks + val BLOCKS_LIST = SINA_BASE_URL + "blocks/blocking.json"//Blocks.GetBlocksList + val BLOCKS_CREATE = SINA_BASE_URL + "blocks/create.json"//Blocks.AddBlock + val BLOCKS_DESTROY = SINA_BASE_URL + "blocks/destroy.json"//Blocks.RemoveBlock + val BLOCKS_EXISTS = SINA_BASE_URL + "blocks/exists.json"//Blocks.IsBlocked + + // Search + val SEARCH_TOPICS = SINA_BASE_URL + "search/topics.json"//Topics.GetSearchTopics + val SEARCH_STATUSES = SINA_BASE_URL + "search/statuses.json"//Search.SearchStatus + val SEARCH_USERS = SINA_BASE_URL + "search/users.json"//Search.SearchUsers + val SEARCH_SUGGESTIONS_AT_USERS = SINA_BASE_URL + "search/suggestions/at_users.json"//Search.SuggestAtUser + + // Friendships + val FRIENDSHIPS_FRIENDS = SINA_BASE_URL + "friendships/friends.json"//Friends.GetFriends + val FRIENDSHIPS_FOLLOWERS = SINA_BASE_URL + "friendships/followers.json"//Friends.GetFollowers + val FRIENDSHIPS_CREATE = SINA_BASE_URL + "friendships/create.json"//Friends.Follow + val FRIENDSHIPS_DESTROY = SINA_BASE_URL + "friendships/destroy.json"//Friends.UnFollow + val FRIENDSHIPS_FRIENDS_IN_COMMON = SINA_BASE_URL + "friendships/friends/in_common.json"//Friends.GetFriendsInCommon + val FRIENDSHIPS_FRIENDS_BILATERAL = SINA_BASE_URL + "friendships/friends/bilateral.json"//Friends.GetBliateral + val FRIENDSHIPS_FOLLOWERS_ACTIVE = SINA_BASE_URL + "friendships/followers/active.json"//Friends.GetActiveFollowers + val FRIENDSHIPS_FRIENDS_CHAIN = SINA_BASE_URL + "friendships/friends_chain/followers.json"//Friends.GetFriendsChain + val FRIENDSHIPS_GROUPS = SINA_BASE_URL + "friendships/groups.json"//Groups.GetGroups + val FRIENDSHIPS_GROUPS_IS_MEMBER = SINA_BASE_URL + "friendships/groups/is_member.json"//Groups.IsMember + val FRIENDSHIPS_GROUPS_TIMELINE = SINA_BASE_URL + "friendships/groups/timeline.json"//Groups.GetGroupTimeline + val FRIENDSHIPS_GROUPS_CREATE = SINA_BASE_URL + "friendships/groups/create.json"//Groups.CreateGroup + val FRIENDSHIPS_GROUPS_DESTROY = SINA_BASE_URL + "friendships/groups/destroy.json"//Groups.DeleteGroup + val FRIENDSHIPS_GROUPS_MEMBERS_ADD = SINA_BASE_URL + "friendships/groups/members/add.json"//Groups.AddToGroup + val FRIENDSHIPS_GROUPS_MEMBERS_DESTROY = SINA_BASE_URL + "friendships/groups/members/destroy.json"//Groups.RemoveFromGroup + + // Direct Message + val DIRECT_MESSAGES = SINA_BASE_URL + "direct_messages.json"//DirectMessages.GetDirectMessages + val DIRECT_MESSAGES_USER_LIST = SINA_BASE_URL + "direct_messages/user_list.json"//DirectMessage.GetUserList + val DIRECT_MESSAGES_CONVERSATION = SINA_BASE_URL + "direct_messages/conversation.json"//DirectMessage.GetConversation + val DIRECT_MESSAGES_SEND = SINA_BASE_URL + "direct_messages/new.json"//DirectMessage.Send + val DIRECT_MESSAGES_THUMB_PIC = "https://upload.api.weibo.com/2/mss/msget_thumbnail?fid=%d&access_token=%s&high=%d&width=%d"//TODO: replace %d and %s + val DIRECT_MESSAGES_ORIG_PIC = "https://upload.api.weibo.com/2/mss/msget?fid=%d&access_token=%s"//TODO: replace %d and %s + val DIRECT_MESSAGES_UPLOAD_PIC = "https://upload.api.weibo.com/2/mss/upload.json?tuid="//DirectMessage.SendPicture + + // Remind + val REMIND_UNREAD_COUNT = "https://rm.api.weibo.com/2/remind/unread_count.json"//Remind.GetUnRead + val REMIND_UNREAD_SET_COUNT = "https://rm.api.weibo.com/2/remind/set_count.json"//Remind.ClearUnRead + + // Attitude + val ATTITUDE_CREATE = SINA_BASE_URL + "attitudes/create.json"//Attitudes.Like + val ATTITUDE_DESTROY = SINA_BASE_URL + "attitudes/destroy.json"//Attitudes.UnLike + + // Short Url + val SHORT_URL_SHORTEN = SINA_BASE_URL + "short_url/shorten.json"//ShortUrl.Shorten + val SHORT_URL_EXPAND = SINA_BASE_URL + "short_url/expand.json"//ShortUrl.Expand + val SHORT_URL_INFO = SINA_BASE_URL + "short_url/info.json"//ShortUrl.Info +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/Entity.java b/app/src/main/java/moe/tlaster/openween/core/api/Entity.java deleted file mode 100644 index 78f3378..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/Entity.java +++ /dev/null @@ -1,28 +0,0 @@ -package moe.tlaster.openween.core.api; - -import android.text.TextUtils; - -import moe.tlaster.openween.App; -import moe.tlaster.openween.common.helpers.SettingHelper; - -/** - * Created by Tlaster on 2016/9/3. - */ -public class Entity { - private static String mAccessToken; - public static String getAccessToken() { - return mAccessToken; - //return SettingHelper.getListSetting(App.getContext(), SettingHelper.ACCESSTOKEN)[0]; - } - - public static void setAccessToken(String accessToken){ - mAccessToken = accessToken; - } - - //public static void setAccessToken(String mAccessToken) { - // Entity.mAccessToken = mAccessToken; - //} - public static String getOauthLoginPage(String appid, String appSecret, String redirectUri, String packageName, String scope){ - return Constants.OAUTH2_ACCESS_AUTHORIZE+"client_id="+appid+"&response_type=token&redirect_uri="+redirectUri+"&key_hash="+appSecret+(TextUtils.isEmpty(packageName) ? "" : "&packagename="+packageName)+"&display=mobile&scope="+scope; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/Entity.kt b/app/src/main/java/moe/tlaster/openween/core/api/Entity.kt new file mode 100644 index 0000000..24b8375 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/Entity.kt @@ -0,0 +1,21 @@ +package moe.tlaster.openween.core.api + +import android.text.TextUtils + +import moe.tlaster.openween.App +import moe.tlaster.openween.common.helpers.SettingHelper + +/** + * Created by Tlaster on 2016/9/3. + */ +object Entity { + //return SettingHelper.getListSetting(App.getContext(), SettingHelper.ACCESSTOKEN)[0]; + var accessToken: String? = null + + //public static void setAccessToken(String mAccessToken) { + // Entity.mAccessToken = mAccessToken; + //} + fun getOauthLoginPage(appid: String, appSecret: String, redirectUri: String, packageName: String, scope: String): String { + return Constants.OAUTH2_ACCESS_AUTHORIZE + "client_id=" + appid + "&response_type=token&redirect_uri=" + redirectUri + "&key_hash=" + appSecret + (if (TextUtils.isEmpty(packageName)) "" else "&packagename=" + packageName) + "&display=mobile&scope=" + scope + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/attitudes/Attitudes.java b/app/src/main/java/moe/tlaster/openween/core/api/attitudes/Attitudes.java deleted file mode 100644 index 308f258..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/attitudes/Attitudes.java +++ /dev/null @@ -1,26 +0,0 @@ -package moe.tlaster.openween.core.api.attitudes; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class Attitudes { - public static void like(long id, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("attitude", "smile"); - param.put("id", String.valueOf(id)); - HttpHelper.postAsync(Constants.ATTITUDE_CREATE, param, callback); - } - public static void unLike(long id, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("id", String.valueOf(id)); - HttpHelper.postAsync(Constants.ATTITUDE_DESTROY, param, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/attitudes/Attitudes.kt b/app/src/main/java/moe/tlaster/openween/core/api/attitudes/Attitudes.kt new file mode 100644 index 0000000..4ab9364 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/attitudes/Attitudes.kt @@ -0,0 +1,38 @@ +package moe.tlaster.openween.core.api.attitudes + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/2. + */ +object Attitudes { + fun like(id: Long, callback: JsonCallback) { + val param = HashMap() + param.put("attitude", "smile") + param.put("id", id.toString()) + HttpHelper.postAsync(Constants.ATTITUDE_CREATE, param, callback) + } + + fun unLike(id: Long, callback: JsonCallback) { + val param = HashMap() + param.put("id", id.toString()) + HttpHelper.postAsync(Constants.ATTITUDE_DESTROY, param, callback) + } + fun likeToMe(callback: JsonCallback, with_common_attitude: Boolean = true, with_comment: Boolean = true, since_id: Long = 0, max_id: Long = 0, count: Int = 20, page: Int = 1) { + val param = HashMap() + param.put("with_common_attitude", if (with_common_attitude) "1" else "0") + param.put("with_comment", if (with_comment) "1" else "0") + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("source", "211160679") + param.put("from", "1055095010") + + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/blocks/Blocks.java b/app/src/main/java/moe/tlaster/openween/core/api/blocks/Blocks.java deleted file mode 100644 index 10dc097..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/blocks/Blocks.java +++ /dev/null @@ -1,46 +0,0 @@ -package moe.tlaster.openween.core.api.blocks; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.block.BlockListModel; -import moe.tlaster.openween.core.model.user.UserModel; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/5. - */ -public class Blocks { - public static void getBlocksList(int count, int page, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - HttpHelper.getAsync(Constants.BLOCKS_LIST, param, callback); - } - public static void getBlocksList(JsonCallback callback) { - getBlocksList(50, 1, callback); - } - public static void addBlock(long uid, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", String.valueOf(uid)); - HttpHelper.postAsync(Constants.BLOCKS_CREATE, param, callback); - } - public static void removeBlock(long uid, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", String.valueOf(uid)); - HttpHelper.postAsync(Constants.BLOCKS_DESTROY, param, callback); - } - public static void isBlocked(long uid, boolean invert, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", String.valueOf(uid)); - param.put("invert", invert? "0" : "1"); - HttpHelper.getAsync(Constants.BLOCKS_EXISTS, param, callback); - } - public static void isBlocked(long uid, JsonCallback callback) { - isBlocked(uid, false, callback); - } - -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/blocks/Blocks.kt b/app/src/main/java/moe/tlaster/openween/core/api/blocks/Blocks.kt new file mode 100644 index 0000000..fa6f43e --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/blocks/Blocks.kt @@ -0,0 +1,42 @@ +package moe.tlaster.openween.core.api.blocks + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.block.BlockListModel +import moe.tlaster.openween.core.model.user.UserModel +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/5. + */ +object Blocks { + fun getBlocksList(count: Int = 50, page: Int = 1, callback: JsonCallback) { + val param = HashMap() + param.put("count", count.toString()) + param.put("page", page.toString()) + HttpHelper.getAsync(Constants.BLOCKS_LIST, param, callback) + } + + fun addBlock(uid: Long, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid.toString()) + HttpHelper.postAsync(Constants.BLOCKS_CREATE, param, callback) + } + + fun removeBlock(uid: Long, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid.toString()) + HttpHelper.postAsync(Constants.BLOCKS_DESTROY, param, callback) + } + + fun isBlocked(uid: Long, invert: Boolean = false, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid.toString()) + param.put("invert", if (invert) "0" else "1") + HttpHelper.getAsync(Constants.BLOCKS_EXISTS, param, callback) + } + +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/comments/Comments.java b/app/src/main/java/moe/tlaster/openween/core/api/comments/Comments.java deleted file mode 100644 index bef4f17..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/comments/Comments.java +++ /dev/null @@ -1,183 +0,0 @@ -package moe.tlaster.openween.core.api.comments; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.comment.CommentListModel; -import moe.tlaster.openween.core.model.comment.CommentModel; -import moe.tlaster.openween.core.model.status.MediaModel; -import moe.tlaster.openween.core.model.types.AuthorType; -import moe.tlaster.openween.core.model.types.SourceType; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/5. - */ -public class Comments { - public static void getCommentStatus(long id, long since_id, long max_id, int count, int page, AuthorType filter_by_author, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("id", String.valueOf(id)); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("since_id", String.valueOf(since_id)); - param.put("max_id", String.valueOf(max_id)); - param.put("filter_by_author", String.valueOf(filter_by_author.getValue())); - HttpHelper.getAsync(Constants.COMMENTS_SHOW, param, callback); - } - public static void getCommentStatus(long id, JsonCallback callBack) { - getCommentStatus(id, 0, 0, 20, 1, AuthorType.All, callBack); - } - public static void getCommentStatus(long id, int count, int page, JsonCallback callBack) { - getCommentStatus(id, 0, 0, count, page, AuthorType.All, callBack); - } - public static void getCommentByMe(long since_id, long max_id, int count, int page, SourceType filter_by_source, JsonCallback callBack) { - Map param = new HashMap<>(); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("since_id", String.valueOf(since_id)); - param.put("max_id", String.valueOf(max_id)); - param.put("filter_by_source", String.valueOf(filter_by_source.getValue())); - HttpHelper.getAsync(Constants.COMMENTS_BY_ME, param, callBack); - } - public static void getCommentByMe(JsonCallback callBack) { - getCommentByMe(0, 0, 50, 1, SourceType.All, callBack); - } - public static void getCommentByMe(int count, int page, JsonCallback callBack) { - getCommentByMe(0, 0, count, page, SourceType.All, callBack); - } - public static void getCommentToMe(long since_id, long max_id, int count, int page, AuthorType filter_by_author, SourceType filter_by_source, JsonCallback callBack) { - Map param = new HashMap<>(); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("since_id", String.valueOf(since_id)); - param.put("max_id", String.valueOf(max_id)); - param.put("filter_by_author", String.valueOf(filter_by_author.getValue())); - param.put("filter_by_source", String.valueOf(filter_by_source.getValue())); - HttpHelper.getAsync(Constants.COMMENTS_TO_ME, param, callBack); - } - public static void getCommentToMe(JsonCallback callback) { - getCommentToMe(0, 0, 50, 1, AuthorType.All, SourceType.All, callback); - } - public static void getCommentToMe(long max_id, int count, JsonCallback callback){ - getCommentToMe(0, max_id, count, 1, AuthorType.All, SourceType.All, callback); - } - public static void getCommentToMe(int count, JsonCallback callback) { - getCommentToMe(0, 0, count, 1, AuthorType.All, SourceType.All, callback); - } - public static void getComment(long since_id, long max_id, int count, int page, int trim_user, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("since_id", String.valueOf(since_id)); - param.put("max_id", String.valueOf(max_id)); - param.put("trim_user", String.valueOf(trim_user)); - HttpHelper.getAsync(Constants.COMMENTS_TIMELINE, param, callback); - } - public static void getComment(JsonCallback callback) { - getComment(0, 0, 50, 1, 0, callback); - } - public static void getComment(int count, int page, JsonCallback callback) { - getComment(0, 0, count, page, 0, callback); - } - public static void getCommentMentions(long since_id, long max_id, int count, int page, AuthorType filter_by_author, SourceType filter_by_source, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("since_id", String.valueOf(since_id)); - param.put("max_id", String.valueOf(max_id)); - param.put("filter_by_author", String.valueOf(filter_by_author.getValue())); - param.put("filter_by_source", String.valueOf(filter_by_source.getValue())); - HttpHelper.getAsync(Constants.COMMENTS_MENTIONS, param, callback); - } - public static void getCommentMentions(JsonCallback callback) { - getCommentMentions(0, 0, 50, 1, AuthorType.All, SourceType.All, callback); - } - - public static void getCommentMentions(long max_id, int count, JsonCallback callback) { - getCommentMentions(0, max_id, count, 1, AuthorType.All, SourceType.All, callback); - } - public static void getCommentMentions(int count, JsonCallback callback) { - getCommentMentions(0, 0, count, 1, AuthorType.All, SourceType.All, callback); - } - public static void batch(JsonCallback> callback, long... cids) { - String cid = ""; - for (long id : cids) { - cid += "," + String.valueOf(id); - } - cid = cid.substring(1); - Map param = new HashMap<>(); - param.put("cids", cid); - HttpHelper.getAsync(Constants.COMMENTS_BATCH, param, callback); - } - public static void postComment(long id, String comment, boolean commentOri, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("id", String.valueOf(id)); - param.put("comment", comment); - param.put("comment_ori", commentOri ? "1" : "0"); - HttpHelper.postAsync(Constants.COMMENTS_CREATE, param, callback); - } - public static void postComment(long id, String comment, JsonCallback callback) { - postComment(id, comment, false, callback); - } - public static void postCommentWithPic(long id, String comment, String pid, boolean commentOri, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("id", String.valueOf(id)); - param.put("comment", comment); - param.put("comment_ori", commentOri ? "1" : "0"); - param.put("media", new MediaModel(pid).toString()); - param.put("source", "211160679"); - param.put("from", "1055095010"); - HttpHelper.postAsync("https://api.weibo.cn/2/comments/create", param, callback); - } - public static void postCommentWithPic(long id, String comment, String pid, JsonCallback callback) { - postCommentWithPic(id, comment, pid, false, callback); - } - - public static void reply(long id, long cid, String comment, boolean comment_ori, boolean without_mention, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("id", String.valueOf(id)); - param.put("cid", String.valueOf(cid)); - param.put("comment", comment); - param.put("comment_ori", comment_ori ? "1" : "0"); - param.put("without_mention", without_mention ? "1" : "0"); - HttpHelper.postAsync(Constants.COMMENTS_REPLY, param, callback); - } - public static void reply(long id, long cid, String comment, JsonCallback callback) { - reply(id, cid, comment, false, false, callback); - } - public static void replyWithPic(long id, long cid, String comment, String pid, boolean comment_ori, boolean without_mention, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("id", String.valueOf(id)); - param.put("cid", String.valueOf(cid)); - param.put("comment", comment); - param.put("comment_ori", comment_ori ? "1" : "0"); - param.put("without_mention", without_mention ? "1" : "0"); - param.put("media", new MediaModel(pid).toString()); - param.put("source", "211160679"); - param.put("from", "1055095010"); - HttpHelper.postAsync("https://api.weibo.cn/2/comments/reply", param, callback); - } - - public static void replyWithPic(long id, long cid, String comment, String pid, JsonCallback callback) { - replyWithPic(id, cid, comment, pid, false, false, callback); - } - public static void delete(long cid, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("cid", String.valueOf(cid)); - HttpHelper.postAsync(Constants.COMMENTS_DESTROY, param, callback); - } - public static void deleteBatch(JsonCallback> callback, long... cids) { - String cid = ""; - for (long id : cids) { - cid += "," + String.valueOf(id); - } - cid = cid.substring(1); - Map param = new HashMap<>(); - param.put("cids", cid); - HttpHelper.postAsync(Constants.COMMENTS_DESTROY_BATCH, param, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/comments/Comments.kt b/app/src/main/java/moe/tlaster/openween/core/api/comments/Comments.kt new file mode 100644 index 0000000..2eb190f --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/comments/Comments.kt @@ -0,0 +1,141 @@ +package moe.tlaster.openween.core.api.comments + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.comment.CommentListModel +import moe.tlaster.openween.core.model.comment.CommentModel +import moe.tlaster.openween.core.model.status.MediaModel +import moe.tlaster.openween.core.model.types.AuthorType +import moe.tlaster.openween.core.model.types.SourceType +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/5. + */ +object Comments { + fun getCommentStatus(id: Long, since_id: Long = 0, max_id: Long = 0, count: Int = 20, page: Int = 1, filter_by_author: AuthorType = AuthorType.All, callback: JsonCallback) { + val param = HashMap() + param.put("id", id.toString()) + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + param.put("filter_by_author", filter_by_author.value.toString()) + HttpHelper.getAsync(Constants.COMMENTS_SHOW, param, callback) + } + + fun getCommentByMe(since_id: Long = 0, max_id: Long = 0, count: Int = 20, page: Int = 1, filter_by_source: SourceType = SourceType.All, callBack: JsonCallback) { + val param = HashMap() + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + param.put("filter_by_source", filter_by_source.value.toString()) + HttpHelper.getAsync(Constants.COMMENTS_BY_ME, param, callBack) + } + + fun getCommentToMe(since_id: Long = 0, max_id: Long = 0, count: Int = 20, page: Int = 1, filter_by_author: AuthorType = AuthorType.All, filter_by_source: SourceType = SourceType.All, callBack: JsonCallback) { + val param = HashMap() + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + param.put("filter_by_author", filter_by_author.value.toString()) + param.put("filter_by_source", filter_by_source.value.toString()) + HttpHelper.getAsync(Constants.COMMENTS_TO_ME, param, callBack) + } + + fun getComment(since_id: Long = 0, max_id: Long = 0, count: Int = 20, page: Int = 1, trim_user: Int = 0, callback: JsonCallback) { + val param = HashMap() + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + param.put("trim_user", trim_user.toString()) + HttpHelper.getAsync(Constants.COMMENTS_TIMELINE, param, callback) + } + + fun getCommentMentions(since_id: Long = 0, max_id: Long = 0, count: Int = 20, page: Int = 1, filter_by_author: AuthorType = AuthorType.All, filter_by_source: SourceType = SourceType.All, callback: JsonCallback) { + val param = HashMap() + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + param.put("filter_by_author", filter_by_author.value.toString()) + param.put("filter_by_source", filter_by_source.value.toString()) + HttpHelper.getAsync(Constants.COMMENTS_MENTIONS, param, callback) + } + + fun batch(callback: JsonCallback>, vararg cids: Long) { + var cid = "" + for (id in cids) { + cid += "," + id.toString() + } + cid = cid.substring(1) + val param = HashMap() + param.put("cids", cid) + HttpHelper.getAsync(Constants.COMMENTS_BATCH, param, callback) + } + + fun postComment(id: Long, comment: String, commentOri: Boolean = false, callback: JsonCallback) { + val param = HashMap() + param.put("id", id.toString()) + param.put("comment", comment) + param.put("comment_ori", if (commentOri) "1" else "0") + HttpHelper.postAsync(Constants.COMMENTS_CREATE, param, callback) + } + + fun postCommentWithPic(id: Long, comment: String, pid: String, commentOri: Boolean = false, callback: JsonCallback) { + val param = HashMap() + param.put("id", id.toString()) + param.put("comment", comment) + param.put("comment_ori", if (commentOri) "1" else "0") + param.put("media", MediaModel(pid).toString()) + param.put("source", "211160679") + param.put("from", "1055095010") + HttpHelper.postAsync("https://api.weibo.cn/2/comments/create", param, callback) + } + + fun reply(id: Long, cid: Long, comment: String, comment_ori: Boolean = false, without_mention: Boolean = false, callback: JsonCallback) { + val param = HashMap() + param.put("id", id.toString()) + param.put("cid", cid.toString()) + param.put("comment", comment) + param.put("comment_ori", if (comment_ori) "1" else "0") + param.put("without_mention", if (without_mention) "1" else "0") + HttpHelper.postAsync(Constants.COMMENTS_REPLY, param, callback) + } + + fun replyWithPic(id: Long, cid: Long, comment: String, pid: String, comment_ori: Boolean = false, without_mention: Boolean = false, callback: JsonCallback) { + val param = HashMap() + param.put("id", id.toString()) + param.put("cid", cid.toString()) + param.put("comment", comment) + param.put("comment_ori", if (comment_ori) "1" else "0") + param.put("without_mention", if (without_mention) "1" else "0") + param.put("media", MediaModel(pid).toString()) + param.put("source", "211160679") + param.put("from", "1055095010") + HttpHelper.postAsync("https://api.weibo.cn/2/comments/reply", param, callback) + } + + fun delete(cid: Long, callback: JsonCallback) { + val param = HashMap() + param.put("cid", cid.toString()) + HttpHelper.postAsync(Constants.COMMENTS_DESTROY, param, callback) + } + + fun deleteBatch(callback: JsonCallback>, vararg cids: Long) { + var cid = "" + for (id in cids) { + cid += "," + id.toString() + } + cid = cid.substring(1) + val param = HashMap() + param.put("cids", cid) + HttpHelper.postAsync(Constants.COMMENTS_DESTROY_BATCH, param, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/directMessage/DirectMessage.java b/app/src/main/java/moe/tlaster/openween/core/api/directMessage/DirectMessage.java deleted file mode 100644 index fb089fc..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/directMessage/DirectMessage.java +++ /dev/null @@ -1,60 +0,0 @@ -package moe.tlaster.openween.core.api.directMessage; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.directmessage.DirectMessageListModel; -import moe.tlaster.openween.core.model.directmessage.DirectMessageModel; -import moe.tlaster.openween.core.model.directmessage.DirectMessageUserListModel; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/6. - */ -public class DirectMessage { - public static void getUserList(int count, int cursor, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("count", String.valueOf(count)); - param.put("cursor", String.valueOf(cursor)); - HttpHelper.getAsync(Constants.DIRECT_MESSAGES_USER_LIST, param, callback); - } - public static void getUserList(JsonCallback callback) { - getUserList(20, 0, callback); - } - public static void getConversation(String uid, long since_id, long max_id, int count, int page, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", uid); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("since_id", String.valueOf(since_id)); - param.put("max_id", String.valueOf(max_id)); - HttpHelper.getAsync(Constants.DIRECT_MESSAGES_CONVERSATION, param, callback); - } - public static void getConversation(String uid, int count, long max_id, JsonCallback callback) { - getConversation(uid, 0, max_id, count, 1, callback); - } - public static void getDirectMessages(long since_id, long max_id, int count, int page, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("since_id", String.valueOf(since_id)); - param.put("max_id", String.valueOf(max_id)); - HttpHelper.getAsync(Constants.DIRECT_MESSAGES, param, callback); - } - public static void getDirectMessages(int count, int page, JsonCallback callback) { - getDirectMessages(0, 0, 20, 1, callback); - } - public static void send(long uid, String text, long id, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", String.valueOf(uid)); - param.put("text", text); - if (id > 0) param.put("id", String.valueOf(id)); - HttpHelper.postAsync(Constants.DIRECT_MESSAGES_SEND, param, callback); - } - public static void send(long uid, String text, JsonCallback callback) { - send(uid, text, -1, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/directMessage/DirectMessage.kt b/app/src/main/java/moe/tlaster/openween/core/api/directMessage/DirectMessage.kt new file mode 100644 index 0000000..0b867fe --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/directMessage/DirectMessage.kt @@ -0,0 +1,50 @@ +package moe.tlaster.openween.core.api.directMessage + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.directmessage.DirectMessageListModel +import moe.tlaster.openween.core.model.directmessage.DirectMessageModel +import moe.tlaster.openween.core.model.directmessage.DirectMessageUserListModel +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/6. + */ +object DirectMessage { + fun getUserList(count: Int = 20, cursor: Int = 0, callback: JsonCallback) { + val param = HashMap() + param.put("count", count.toString()) + param.put("cursor", cursor.toString()) + HttpHelper.getAsync(Constants.DIRECT_MESSAGES_USER_LIST, param, callback) + } + + fun getConversation(uid: String, since_id: Long = 0, max_id: Long = 0, count: Int = 20, page: Int = 1, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid) + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + HttpHelper.getAsync(Constants.DIRECT_MESSAGES_CONVERSATION, param, callback) + } + + fun getDirectMessages(since_id: Long = 0, max_id: Long = 0, count: Int = 20, page: Int = 1, callback: JsonCallback) { + val param = HashMap() + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + HttpHelper.getAsync(Constants.DIRECT_MESSAGES, param, callback) + } + + fun send(uid: Long, text: String, id: Long = -1, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid.toString()) + param.put("text", text) + if (id > 0) param.put("id", id.toString()) + HttpHelper.postAsync(Constants.DIRECT_MESSAGES_SEND, param, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/favorites/Favorites.java b/app/src/main/java/moe/tlaster/openween/core/api/favorites/Favorites.java deleted file mode 100644 index f76afd5..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/favorites/Favorites.java +++ /dev/null @@ -1,52 +0,0 @@ -package moe.tlaster.openween.core.api.favorites; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.favor.FavorListModel; -import moe.tlaster.openween.core.model.favor.FavorModel; -import moe.tlaster.openween.core.model.favor.FavorTagListModel; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/6. - */ -public class Favorites { - public static void getFavorList(int count, int page, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - HttpHelper.getAsync(Constants.FAVORITES_LIST, param, callback); - } - public static void getFavor(long id, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("id", String.valueOf(id)); - HttpHelper.getAsync(Constants.FAVORITES_SHOW, param, callback); - } - public static void getFavorListByTag(long tid, int count, int page, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("tid", String.valueOf(tid)); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - HttpHelper.getAsync(Constants.FAVORITES_LIST_BY_TAG, param, callback); - } - public static void getTags(int count, int page, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - HttpHelper.getAsync(Constants.FAVORITES_TAGS, param, callback); - } - public static void addFavor(long id, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("id", String.valueOf(id)); - HttpHelper.postAsync(Constants.FAVORITES_CREATE, param, callback); - } - public static void removeFavor(long id, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("id", String.valueOf(id)); - HttpHelper.postAsync(Constants.FAVORITES_DESTROY, param, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/favorites/Favorites.kt b/app/src/main/java/moe/tlaster/openween/core/api/favorites/Favorites.kt new file mode 100644 index 0000000..9bd5deb --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/favorites/Favorites.kt @@ -0,0 +1,56 @@ +package moe.tlaster.openween.core.api.favorites + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.favor.FavorListModel +import moe.tlaster.openween.core.model.favor.FavorModel +import moe.tlaster.openween.core.model.favor.FavorTagListModel +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/6. + */ +object Favorites { + fun getFavorList(count: Int, page: Int, callback: JsonCallback) { + val param = HashMap() + param.put("count", count.toString()) + param.put("page", page.toString()) + HttpHelper.getAsync(Constants.FAVORITES_LIST, param, callback) + } + + fun getFavor(id: Long, callback: JsonCallback) { + val param = HashMap() + param.put("id", id.toString()) + HttpHelper.getAsync(Constants.FAVORITES_SHOW, param, callback) + } + + fun getFavorListByTag(tid: Long, count: Int, page: Int, callback: JsonCallback) { + val param = HashMap() + param.put("tid", tid.toString()) + param.put("count", count.toString()) + param.put("page", page.toString()) + HttpHelper.getAsync(Constants.FAVORITES_LIST_BY_TAG, param, callback) + } + + fun getTags(count: Int, page: Int, callback: JsonCallback) { + val param = HashMap() + param.put("count", count.toString()) + param.put("page", page.toString()) + HttpHelper.getAsync(Constants.FAVORITES_TAGS, param, callback) + } + + fun addFavor(id: Long, callback: JsonCallback) { + val param = HashMap() + param.put("id", id.toString()) + HttpHelper.postAsync(Constants.FAVORITES_CREATE, param, callback) + } + + fun removeFavor(id: Long, callback: JsonCallback) { + val param = HashMap() + param.put("id", id.toString()) + HttpHelper.postAsync(Constants.FAVORITES_DESTROY, param, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/friendships/Friends.java b/app/src/main/java/moe/tlaster/openween/core/api/friendships/Friends.java deleted file mode 100644 index 39fa376..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/friendships/Friends.java +++ /dev/null @@ -1,72 +0,0 @@ -package moe.tlaster.openween.core.api.friendships; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.user.UserListModel; -import moe.tlaster.openween.core.model.user.UserModel; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/7. - */ -public class Friends { - private static void getUsers(T uid, int count, int cursor, String url, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", String.valueOf(uid)); - param.put("count", String.valueOf(count)); - param.put("cursor", String.valueOf(cursor)); - HttpHelper.getAsync(url, param, callback); - } - public static void getFriends(long uid, int count, int cursor, JsonCallback callback) { - getUsers(uid, count, cursor, Constants.FRIENDSHIPS_FRIENDS, callback); - } - public static void getFriends(String screen_name, int count, int cursor, JsonCallback callback) { - getUsers(screen_name, count, cursor, Constants.FRIENDSHIPS_FRIENDS, callback); - } - public static void getFriendsInCommon(long uid, long suid, int count, int page, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", String.valueOf(uid)); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - if (suid != -1) param.put("suid", String.valueOf(suid)); - HttpHelper.getAsync(Constants.FRIENDSHIPS_FRIENDS_IN_COMMON, param, callback); - } - public static void getBliateral(long uid, int count, int page, int sort, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", String.valueOf(uid)); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("sort", String.valueOf(sort)); - HttpHelper.getAsync(Constants.FRIENDSHIPS_FRIENDS_BILATERAL, param, callback); - } - public static void getFollowers(long uid, int count, int cursor, JsonCallback callback) { - getUsers(uid, count, cursor, Constants.FRIENDSHIPS_FOLLOWERS, callback); - } - public static void getFollowers(String screen_name, int count, int cursor, JsonCallback callback) { - getUsers(screen_name, count, cursor, Constants.FRIENDSHIPS_FOLLOWERS, callback); - } - public static void follow(long uid, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", String.valueOf(uid)); - HttpHelper.postAsync(Constants.FRIENDSHIPS_CREATE, param, callback); - } - public static void follow(String screen_name, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("screen_name", String.valueOf(screen_name)); - HttpHelper.postAsync(Constants.FRIENDSHIPS_CREATE, param, callback); - } - public static void unfollow(long uid, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", String.valueOf(uid)); - HttpHelper.postAsync(Constants.FRIENDSHIPS_DESTROY, param, callback); - } - public static void unfollow(String screen_name, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("screen_name", String.valueOf(screen_name)); - HttpHelper.postAsync(Constants.FRIENDSHIPS_DESTROY, param, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/friendships/Friends.kt b/app/src/main/java/moe/tlaster/openween/core/api/friendships/Friends.kt new file mode 100644 index 0000000..0aaede8 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/friendships/Friends.kt @@ -0,0 +1,81 @@ +package moe.tlaster.openween.core.api.friendships + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.user.UserListModel +import moe.tlaster.openween.core.model.user.UserModel +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/7. + */ +object Friends { + private fun getUsers(uid: T, count: Int, cursor: Int, url: String, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid.toString()) + param.put("count", count.toString()) + param.put("cursor", cursor.toString()) + HttpHelper.getAsync(url, param, callback) + } + + fun getFriends(uid: Long, count: Int, cursor: Int, callback: JsonCallback) { + getUsers(uid, count, cursor, Constants.FRIENDSHIPS_FRIENDS, callback) + } + + fun getFriends(screen_name: String, count: Int, cursor: Int, callback: JsonCallback) { + getUsers(screen_name, count, cursor, Constants.FRIENDSHIPS_FRIENDS, callback) + } + + fun getFriendsInCommon(uid: Long, suid: Long, count: Int, page: Int, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid.toString()) + param.put("count", count.toString()) + param.put("page", page.toString()) + if (suid != -1L) param.put("suid", suid.toString()) + HttpHelper.getAsync(Constants.FRIENDSHIPS_FRIENDS_IN_COMMON, param, callback) + } + + fun getBliateral(uid: Long, count: Int, page: Int, sort: Int, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid.toString()) + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("sort", sort.toString()) + HttpHelper.getAsync(Constants.FRIENDSHIPS_FRIENDS_BILATERAL, param, callback) + } + + fun getFollowers(uid: Long, count: Int, cursor: Int, callback: JsonCallback) { + getUsers(uid, count, cursor, Constants.FRIENDSHIPS_FOLLOWERS, callback) + } + + fun getFollowers(screen_name: String, count: Int, cursor: Int, callback: JsonCallback) { + getUsers(screen_name, count, cursor, Constants.FRIENDSHIPS_FOLLOWERS, callback) + } + + fun follow(uid: Long, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid.toString()) + HttpHelper.postAsync(Constants.FRIENDSHIPS_CREATE, param, callback) + } + + fun follow(screen_name: String, callback: JsonCallback) { + val param = HashMap() + param.put("screen_name", screen_name) + HttpHelper.postAsync(Constants.FRIENDSHIPS_CREATE, param, callback) + } + + fun unfollow(uid: Long, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid.toString()) + HttpHelper.postAsync(Constants.FRIENDSHIPS_DESTROY, param, callback) + } + + fun unfollow(screen_name: String, callback: JsonCallback) { + val param = HashMap() + param.put("screen_name", screen_name) + HttpHelper.postAsync(Constants.FRIENDSHIPS_DESTROY, param, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/friendships/Groups.java b/app/src/main/java/moe/tlaster/openween/core/api/friendships/Groups.java deleted file mode 100644 index 826a3f3..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/friendships/Groups.java +++ /dev/null @@ -1,34 +0,0 @@ -package moe.tlaster.openween.core.api.friendships; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.status.GroupListModel; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.model.status.MessageListModel; -import moe.tlaster.openween.core.model.types.FeatureType; - -/** - * Created by Tlaster on 2016/9/7. - */ -public class Groups { - public static void getGroups(JsonCallback callback) { - HttpHelper.getAsync(Constants.FRIENDSHIPS_GROUPS, null, callback); - } - public static void getGroupTimeline(String list_id, long max_id, int count, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(1)); - param.put("since_id", String.valueOf(0)); - param.put("max_id", String.valueOf(max_id)); - param.put("list_id", list_id); - param.put("feature", String.valueOf(FeatureType.All.getValue())); - HttpHelper.getAsync(Constants.FRIENDSHIPS_GROUPS_TIMELINE, param, callback); - } - public static void getGroupTimeline(String list_id, int count, JsonCallback callback) { - getGroupTimeline(list_id, 0, count, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/friendships/Groups.kt b/app/src/main/java/moe/tlaster/openween/core/api/friendships/Groups.kt new file mode 100644 index 0000000..17e7de9 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/friendships/Groups.kt @@ -0,0 +1,31 @@ +package moe.tlaster.openween.core.api.friendships + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.status.GroupListModel +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.model.status.MessageListModel +import moe.tlaster.openween.core.model.types.FeatureType + +/** + * Created by Tlaster on 2016/9/7. + */ +object Groups { + fun getGroups(callback: JsonCallback) { + HttpHelper.getAsync(Constants.FRIENDSHIPS_GROUPS, null, callback) + } + + fun getGroupTimeline(list_id: String, max_id: Long = 0, count: Int = 20, callback: JsonCallback) { + val param = HashMap() + param.put("count", count.toString()) + param.put("page", 1.toString()) + param.put("since_id", 0.toString()) + param.put("max_id", max_id.toString()) + param.put("list_id", list_id) + param.put("feature", FeatureType.All.value.toString()) + HttpHelper.getAsync(Constants.FRIENDSHIPS_GROUPS_TIMELINE, param, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/remind/Remind.java b/app/src/main/java/moe/tlaster/openween/core/api/remind/Remind.java deleted file mode 100644 index 7c3a339..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/remind/Remind.java +++ /dev/null @@ -1,31 +0,0 @@ -package moe.tlaster.openween.core.api.remind; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.UnreadModel; -import moe.tlaster.openween.core.model.types.RemindType; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/7. - */ -public class Remind { - public static void getUnread(String uid, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", String.valueOf(uid)); - param.put("unread_message", "0"); - HttpHelper.getAsync(Constants.REMIND_UNREAD_COUNT, param, callback); - } - public static void getUnread(JsonCallback callback) { - HttpHelper.getAsync(Constants.REMIND_UNREAD_COUNT, null, callback); - } - public static void clearUnread(RemindType type) { - Map param = new HashMap<>(); - param.put("type", type.toString()); - HttpHelper.postAsync(Constants.REMIND_UNREAD_SET_COUNT, param, null); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/remind/Remind.kt b/app/src/main/java/moe/tlaster/openween/core/api/remind/Remind.kt new file mode 100644 index 0000000..69c0540 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/remind/Remind.kt @@ -0,0 +1,32 @@ +package moe.tlaster.openween.core.api.remind + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.UnreadModel +import moe.tlaster.openween.core.model.types.RemindType +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/7. + */ +object Remind { + fun getUnread(uid: String, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid.toString()) + param.put("unread_message", "0") + HttpHelper.getAsync(Constants.REMIND_UNREAD_COUNT, param, callback) + } + + fun getUnread(callback: JsonCallback) { + HttpHelper.getAsync(Constants.REMIND_UNREAD_COUNT, null, callback) + } + + fun clearUnread(type: RemindType) { + val param = HashMap() + param.put("type", type.toString()) + HttpHelper.postAsync(Constants.REMIND_UNREAD_SET_COUNT, param, null) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/shortUrl/ShortUrl.java b/app/src/main/java/moe/tlaster/openween/core/api/shortUrl/ShortUrl.java deleted file mode 100644 index f86ddf2..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/shortUrl/ShortUrl.java +++ /dev/null @@ -1,32 +0,0 @@ -package moe.tlaster.openween.core.api.shortUrl; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.url.UrlInfoListModel; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/7. - */ -public class ShortUrl { - public static void shorten(String url, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("url_long", url); - HttpHelper.getAsync(Constants.SHORT_URL_SHORTEN, param, callback); - } - public static void expand(String url, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("url_short", url); - HttpHelper.getAsync(Constants.SHORT_URL_EXPAND, param, callback); - } - public static void info(JsonCallback callback, String... urls) { - Map param = new HashMap<>(); - for (String url : urls) { - param.put("url_short", url); - } - HttpHelper.getAsync(Constants.SHORT_URL_INFO, param, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/shortUrl/ShortUrl.kt b/app/src/main/java/moe/tlaster/openween/core/api/shortUrl/ShortUrl.kt new file mode 100644 index 0000000..16b9a7d --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/shortUrl/ShortUrl.kt @@ -0,0 +1,33 @@ +package moe.tlaster.openween.core.api.shortUrl + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.url.UrlInfoListModel +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/7. + */ +object ShortUrl { + fun shorten(url: String, callback: JsonCallback) { + val param = HashMap() + param.put("url_long", url) + HttpHelper.getAsync(Constants.SHORT_URL_SHORTEN, param, callback) + } + + fun expand(url: String, callback: JsonCallback) { + val param = HashMap() + param.put("url_short", url) + HttpHelper.getAsync(Constants.SHORT_URL_EXPAND, param, callback) + } + + fun info(callback: JsonCallback, vararg urls: String) { + val param = HashMap() + for (url in urls) { + param.put("url_short", url) + } + HttpHelper.getAsync(Constants.SHORT_URL_INFO, param, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Emotions.java b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Emotions.java deleted file mode 100644 index 78090aa..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Emotions.java +++ /dev/null @@ -1,18 +0,0 @@ -package moe.tlaster.openween.core.api.statuses; - -import java.util.List; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.EmotionModel; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/7. - */ -public class Emotions { - public static void getEmotions(JsonCallback> callback) { - HttpHelper.getAsync(Constants.EMOTIONS, null, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Emotions.kt b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Emotions.kt new file mode 100644 index 0000000..91c184e --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Emotions.kt @@ -0,0 +1,16 @@ +package moe.tlaster.openween.core.api.statuses + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.EmotionModel +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/7. + */ +object Emotions { + fun getEmotions(callback: JsonCallback>) { + HttpHelper.getAsync(Constants.EMOTIONS, null, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Home.java b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Home.java deleted file mode 100644 index bb59d5c..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Home.java +++ /dev/null @@ -1,34 +0,0 @@ -package moe.tlaster.openween.core.api.statuses; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.status.MessageListModel; -import moe.tlaster.openween.core.model.types.FeatureType; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/7. - */ -public class Home { - public static void getTimeline(int count, int page, long max_id, long since_id, int base_app, FeatureType feature, int trim_user, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("since_id", String.valueOf(since_id)); - param.put("max_id", String.valueOf(max_id)); - param.put("base_app", String.valueOf(base_app)); - param.put("trim_user", String.valueOf(trim_user)); - param.put("feature", String.valueOf(feature.getValue())); - HttpHelper.getAsync(Constants.HOME_TIMELINE, param, callback); - } - public static void getTimeline(int count, JsonCallback callback) { - getTimeline(count, 1, 0, 0, 0, FeatureType.All, 0, callback); - } - public static void getTimeline(int count, long max_id, JsonCallback callback) { - getTimeline(count, 1, max_id, 0, 0, FeatureType.All, 0, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Home.kt b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Home.kt new file mode 100644 index 0000000..44fd149 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Home.kt @@ -0,0 +1,27 @@ +package moe.tlaster.openween.core.api.statuses + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.status.MessageListModel +import moe.tlaster.openween.core.model.types.FeatureType +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/7. + */ +object Home { + fun getTimeline(count: Int = 20, page: Int = 1, max_id: Long = 0, since_id: Long = 0, base_app: Int = 0, feature: FeatureType = FeatureType.All, trim_user: Int = 0, callback: JsonCallback) { + val param = HashMap() + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + param.put("base_app", base_app.toString()) + param.put("trim_user", trim_user.toString()) + param.put("feature", feature.value.toString()) + HttpHelper.getAsync(Constants.HOME_TIMELINE, param, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Mentions.java b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Mentions.java deleted file mode 100644 index 1103272..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Mentions.java +++ /dev/null @@ -1,37 +0,0 @@ -package moe.tlaster.openween.core.api.statuses; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.status.MessageListModel; -import moe.tlaster.openween.core.model.types.AuthorType; -import moe.tlaster.openween.core.model.types.FeatureType; -import moe.tlaster.openween.core.model.types.SourceType; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/7. - */ -public class Mentions { - public static void getMentions(long since_id, long max_id, int count, int page, AuthorType filter_by_author, SourceType filter_by_source, FeatureType filter_by_type, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("since_id", String.valueOf(since_id)); - param.put("max_id", String.valueOf(max_id)); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("filter_by_author", String.valueOf(filter_by_author.getValue())); - param.put("filter_by_source", String.valueOf(filter_by_source.getValue())); - param.put("filter_by_type", String.valueOf(filter_by_type.getValue())); - HttpHelper.getAsync(Constants.MENTIONS, param, callback); - } - public static void getMentions(int count, JsonCallback callback) { - getMentions(0, 0, count, 1, AuthorType.All, SourceType.All, FeatureType.All, callback); - } - public static void getMentions(long max_id, int count, JsonCallback callback){ - getMentions(0, max_id, count, 1, AuthorType.All, SourceType.All, FeatureType.All, callback); - } - -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Mentions.kt b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Mentions.kt new file mode 100644 index 0000000..c8ca090 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Mentions.kt @@ -0,0 +1,30 @@ +package moe.tlaster.openween.core.api.statuses + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.status.MessageListModel +import moe.tlaster.openween.core.model.types.AuthorType +import moe.tlaster.openween.core.model.types.FeatureType +import moe.tlaster.openween.core.model.types.SourceType +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/7. + */ +object Mentions { + fun getMentions(since_id: Long = 0, max_id: Long = 0, count: Int = 20, page: Int = 1, filter_by_author: AuthorType = AuthorType.All, filter_by_source: SourceType = SourceType.All, filter_by_type: FeatureType = FeatureType.All, callback: JsonCallback) { + val param = HashMap() + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("filter_by_author", filter_by_author.value.toString()) + param.put("filter_by_source", filter_by_source.value.toString()) + param.put("filter_by_type", filter_by_type.value.toString()) + HttpHelper.getAsync(Constants.MENTIONS, param, callback) + } + +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/PostWeibo.java b/app/src/main/java/moe/tlaster/openween/core/api/statuses/PostWeibo.java deleted file mode 100644 index 1734914..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/statuses/PostWeibo.java +++ /dev/null @@ -1,91 +0,0 @@ -package moe.tlaster.openween.core.api.statuses; - -import android.support.annotation.Nullable; -import android.text.TextUtils; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.status.MediaModel; -import moe.tlaster.openween.core.model.status.MessageModel; -import moe.tlaster.openween.core.model.status.PictureModel; -import moe.tlaster.openween.core.model.types.RepostType; -import moe.tlaster.openween.core.model.types.WeiboVisibility; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/8. - */ -public class PostWeibo { - public static void post(String status, WeiboVisibility visible, String list_id, float plat, float plong, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("status", status); - param.put("visible", String.valueOf(visible.getValue())); - param.put("lat", String.valueOf(plat)); - param.put("long", String.valueOf(plong)); - param = checkForVisibility(visible, list_id, param); - HttpHelper.postAsync(Constants.UPDATE, param, callback); - } - public static void post(String status, JsonCallback callback) { - post(status, WeiboVisibility.All, "", 0, 0, callback); - } - public static void postWithPic(String status, File pic, WeiboVisibility visible, String list_id, float plat, float plong, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("status", status); - param.put("visible", String.valueOf(visible.getValue())); - param.put("lat", String.valueOf(plat)); - param.put("long", String.valueOf(plong)); - param = checkForVisibility(visible, list_id, param); - HttpHelper.uploadFileWithParamAsync(Constants.UPLOAD, pic, param, callback); - } - public static void repost(long id, String status, RepostType is_comment, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("status", TextUtils.isEmpty(status) ? "转发微博" : status); - param.put("id", String.valueOf(id)); - param.put("is_comment", String.valueOf(is_comment.getValue())); - HttpHelper.postAsync(Constants.REPOST, param, callback); - } - - public static void repostWithPic(long id, String status, String pid, RepostType is_comment, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("status", TextUtils.isEmpty(status) ? "转发微博" : status); - param.put("id", String.valueOf(id)); - param.put("is_comment", String.valueOf(is_comment.getValue())); - param.put("media", new MediaModel(pid).toString()); - param.put("source", "211160679"); - param.put("from", "1055095010"); - HttpHelper.postAsync("https://api.weibo.cn/2/statuses/repost", param, callback); - } - public static void deletePost(long id, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("id", String.valueOf(id)); - HttpHelper.postAsync(Constants.DESTROY, param, callback); - } - public static void uploadPicture(File file, JsonCallback callback) { - HttpHelper.uploadFileAsync(Constants.UPLOAD_PIC, file, callback); - } - public static void postWithMultiPics(String status, String pics, WeiboVisibility visible, String list_id, float plat, float plong, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("status", status); - param.put("pic_id", pics); - param.put("visible", String.valueOf(visible.getValue())); - param.put("lat", String.valueOf(plat)); - param.put("long", String.valueOf(plong)); - param = checkForVisibility(visible, list_id, param); - HttpHelper.postAsync(Constants.UPLOAD_URL_TEXT, param, callback); - } - public static void postWithMultiPics(String status, String pics, JsonCallback callback) { - postWithMultiPics(status, pics, WeiboVisibility.All, "", 0 ,0, callback); - } - @Nullable - private static Map checkForVisibility(WeiboVisibility visible, String list_id, Map param){ - if (visible == WeiboVisibility.SpecifiedGroup) - if(!TextUtils.isEmpty(list_id)) - param.put("list_id", list_id); - return param; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/PostWeibo.kt b/app/src/main/java/moe/tlaster/openween/core/api/statuses/PostWeibo.kt new file mode 100644 index 0000000..966f495 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/statuses/PostWeibo.kt @@ -0,0 +1,88 @@ +package moe.tlaster.openween.core.api.statuses + +import android.text.TextUtils + +import java.io.File +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.status.MediaModel +import moe.tlaster.openween.core.model.status.MessageModel +import moe.tlaster.openween.core.model.status.PictureModel +import moe.tlaster.openween.core.model.types.RepostType +import moe.tlaster.openween.core.model.types.WeiboVisibility +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/8. + */ +object PostWeibo { + fun post(status: String, visible: WeiboVisibility = WeiboVisibility.All, list_id: String = "", plat: Float = 0f, plong: Float = 0f, callback: JsonCallback) { + var param: MutableMap = HashMap() + param.put("status", status) + param.put("visible", visible.value.toString()) + param.put("lat", plat.toString()) + param.put("long", plong.toString()) + param = checkForVisibility(visible, list_id, param) + HttpHelper.postAsync(Constants.UPDATE, param, callback) + } + + fun postWithPic(status: String, pic: File, visible: WeiboVisibility, list_id: String, plat: Float, plong: Float, callback: JsonCallback) { + var param: MutableMap = HashMap() + param.put("status", status) + param.put("visible", visible.value.toString()) + param.put("lat", plat.toString()) + param.put("long", plong.toString()) + param = checkForVisibility(visible, list_id, param) + HttpHelper.uploadFileWithParamAsync(Constants.UPLOAD, pic, param, callback) + } + + fun repost(id: Long, status: String, is_comment: RepostType = RepostType.None, callback: JsonCallback) { + val param = HashMap() + param.put("status", if (TextUtils.isEmpty(status)) "转发微博" else status) + param.put("id", id.toString()) + param.put("is_comment", is_comment.value.toString()) + HttpHelper.postAsync(Constants.REPOST, param, callback) + } + + fun repostWithPic(id: Long, status: String, pid: String, is_comment: RepostType = RepostType.None, callback: JsonCallback) { + val param = HashMap() + param.put("status", if (TextUtils.isEmpty(status)) "转发微博" else status) + param.put("id", id.toString()) + param.put("is_comment", is_comment.value.toString()) + param.put("media", MediaModel(pid).toString()) + param.put("source", "211160679") + param.put("from", "1055095010") + HttpHelper.postAsync("https://api.weibo.cn/2/statuses/repost", param, callback) + } + + fun deletePost(id: Long, callback: JsonCallback) { + val param = HashMap() + param.put("id", id.toString()) + HttpHelper.postAsync(Constants.DESTROY, param, callback) + } + + fun uploadPicture(file: File, callback: JsonCallback) { + HttpHelper.uploadFileAsync(Constants.UPLOAD_PIC, file, callback) + } + + fun postWithMultiPics(status: String, pics: String, visible: WeiboVisibility = WeiboVisibility.All, list_id: String = "", plat: Float = 0f, plong: Float = 0f, callback: JsonCallback) { + var param: MutableMap = HashMap() + param.put("status", status) + param.put("pic_id", pics) + param.put("visible", visible.value.toString()) + param.put("lat", plat.toString()) + param.put("long", plong.toString()) + param = checkForVisibility(visible, list_id, param) + HttpHelper.postAsync(Constants.UPLOAD_URL_TEXT, param, callback) + } + + private fun checkForVisibility(visible: WeiboVisibility, list_id: String, param: MutableMap): MutableMap { + if (visible === WeiboVisibility.SpecifiedGroup) + if (!TextUtils.isEmpty(list_id)) + param.put("list_id", list_id) + return param + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Query.java b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Query.java deleted file mode 100644 index 1271dd3..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Query.java +++ /dev/null @@ -1,22 +0,0 @@ -package moe.tlaster.openween.core.api.statuses; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.status.MessageModel; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/8. - */ -public class Query { - public static void getStatus(long id, boolean isGetLongText, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("id", String.valueOf(id)); - param.put("isGetLongText", isGetLongText ? "1" : "0"); - HttpHelper.getAsync(Constants.SHOW, param, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Query.kt b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Query.kt new file mode 100644 index 0000000..5b7a6cd --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Query.kt @@ -0,0 +1,21 @@ +package moe.tlaster.openween.core.api.statuses + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.status.MessageModel +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/8. + */ +object Query { + fun getStatus(id: Long, isGetLongText: Boolean, callback: JsonCallback) { + val param = HashMap() + param.put("id", id.toString()) + param.put("isGetLongText", if (isGetLongText) "1" else "0") + HttpHelper.getAsync(Constants.SHOW, param, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Repost.java b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Repost.java deleted file mode 100644 index c5aee9f..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Repost.java +++ /dev/null @@ -1,30 +0,0 @@ -package moe.tlaster.openween.core.api.statuses; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.status.RepostListModel; -import moe.tlaster.openween.core.model.types.AuthorType; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/9. - */ -public class Repost { - public static void getRepost(long id, long since_id, long max_id, int count, int page, AuthorType filter_by_author, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("id", String.valueOf(id)); - param.put("since_id", String.valueOf(since_id)); - param.put("max_id", String.valueOf(max_id)); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("filter_by_author", String.valueOf(filter_by_author.getValue())); - HttpHelper.getAsync(Constants.REPOST_TIMELINE, param, callback); - } - public static void getRepost(long id, int count, int page, JsonCallback callback) { - getRepost(id, 0, 0, count, page, AuthorType.All, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/Repost.kt b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Repost.kt new file mode 100644 index 0000000..70462a2 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/statuses/Repost.kt @@ -0,0 +1,26 @@ +package moe.tlaster.openween.core.api.statuses + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.status.RepostListModel +import moe.tlaster.openween.core.model.types.AuthorType +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/9. + */ +object Repost { + fun getRepost(id: Long, since_id: Long = 0, max_id: Long = 0, count: Int = 20, page: Int = 1, filter_by_author: AuthorType = AuthorType.All, callback: JsonCallback) { + val param = HashMap() + param.put("id", id.toString()) + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("filter_by_author", filter_by_author.value.toString()) + HttpHelper.getAsync(Constants.REPOST_TIMELINE, param, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/UserTimeline.java b/app/src/main/java/moe/tlaster/openween/core/api/statuses/UserTimeline.java deleted file mode 100644 index 66e3073..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/statuses/UserTimeline.java +++ /dev/null @@ -1,60 +0,0 @@ -package moe.tlaster.openween.core.api.statuses; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.status.MessageListModel; -import moe.tlaster.openween.core.model.types.FeatureType; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/9. - */ -public class UserTimeline { - public static void getUserTimeline(long uid, int count, int page, long max_id, long since_id, int base_app, FeatureType feature, int trim_user, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", String.valueOf(uid)); - param.put("since_id", String.valueOf(since_id)); - param.put("max_id", String.valueOf(max_id)); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("base_app", String.valueOf(base_app)); - param.put("feature", String.valueOf(feature.getValue())); - param.put("trim_user", String.valueOf(trim_user)); - param.put("source", "211160679"); - param.put("from", "1055095010"); - HttpHelper.getAsync("https://api.weibo.cn/2/statuses/user_timeline", param, callback); - } - public static void getUserTimeline(long uid, int count, int page, JsonCallback callback) { - getUserTimeline(uid, count, page, 0, 0, 0, FeatureType.All, 0, callback); - } - public static void getUserTimeline(long uid, int count, long max_id, JsonCallback callback){ - getUserTimeline(uid, count, 1, max_id, 0, 0, FeatureType.All, 0, callback); - } - public static void getUserTimeline(long uid, int count, JsonCallback callback){ - getUserTimeline(uid, count, 1, 0, 0, 0, FeatureType.All, 0, callback); - } - - - public static void getUserTimeline(String screen_name, int count, int page, long max_id, long since_id, int base_app, FeatureType feature, int trim_user, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("screen_name", String.valueOf(screen_name)); - param.put("since_id", String.valueOf(since_id)); - param.put("max_id", String.valueOf(max_id)); - param.put("count", String.valueOf(count)); - param.put("page", String.valueOf(page)); - param.put("base_app", String.valueOf(base_app)); - param.put("feature", String.valueOf(feature.getValue())); - param.put("trim_user", String.valueOf(trim_user)); - param.put("source", "211160679"); - param.put("from", "1055095010"); - HttpHelper.getAsync("https://api.weibo.cn/2/statuses/user_timeline", param, callback); - } - public static void getUserTimeline(String screen_name, int count, int page, JsonCallback callback) { - getUserTimeline(screen_name, count, page, 0, 0, 0, FeatureType.All, 0, callback); - } - -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/statuses/UserTimeline.kt b/app/src/main/java/moe/tlaster/openween/core/api/statuses/UserTimeline.kt new file mode 100644 index 0000000..ae21fb6 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/statuses/UserTimeline.kt @@ -0,0 +1,45 @@ +package moe.tlaster.openween.core.api.statuses + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.status.MessageListModel +import moe.tlaster.openween.core.model.types.FeatureType +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/9. + */ +object UserTimeline { + fun getUserTimeline(uid: Long, count: Int = 20, page: Int = 1, max_id: Long = 0, since_id: Long = 0, base_app: Int = 0, feature: FeatureType = FeatureType.All, trim_user: Int = 0, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid.toString()) + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("base_app", base_app.toString()) + param.put("feature", feature.value.toString()) + param.put("trim_user", trim_user.toString()) + param.put("source", "211160679") + param.put("from", "1055095010") + HttpHelper.getAsync("https://api.weibo.cn/2/statuses/user_timeline", param, callback) + } + + fun getUserTimeline(screen_name: String, count: Int = 20, page: Int = 1, max_id: Long = 0, since_id: Long = 0, base_app: Int = 0, feature: FeatureType = FeatureType.All, trim_user: Int = 0, callback: JsonCallback) { + val param = HashMap() + param.put("screen_name", screen_name.toString()) + param.put("since_id", since_id.toString()) + param.put("max_id", max_id.toString()) + param.put("count", count.toString()) + param.put("page", page.toString()) + param.put("base_app", base_app.toString()) + param.put("feature", feature.value.toString()) + param.put("trim_user", trim_user.toString()) + param.put("source", "211160679") + param.put("from", "1055095010") + HttpHelper.getAsync("https://api.weibo.cn/2/statuses/user_timeline", param, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/user/Account.java b/app/src/main/java/moe/tlaster/openween/core/api/user/Account.java deleted file mode 100644 index 83d7860..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/user/Account.java +++ /dev/null @@ -1,22 +0,0 @@ -package moe.tlaster.openween.core.api.user; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.model.LimitStatusModel; - -/** - * Created by Tlaster on 2016/9/9. - */ -public class Account { - public static void getUid(JsonCallback callback) { - HttpHelper.getAsync(Constants.GET_UID, null, callback); - } - public static void getUid(String token, JsonCallback callback) { - HttpHelper.getAsync(Constants.GET_UID, token, null, callback); - } - public static void getLimitStatus(JsonCallback callback) { - HttpHelper.getAsync(Constants.RATE_LIMIT_STATUS, null, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/user/Account.kt b/app/src/main/java/moe/tlaster/openween/core/api/user/Account.kt new file mode 100644 index 0000000..da5a49b --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/user/Account.kt @@ -0,0 +1,24 @@ +package moe.tlaster.openween.core.api.user + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.model.LimitStatusModel + +/** + * Created by Tlaster on 2016/9/9. + */ +object Account { + fun getUid(callback: JsonCallback) { + HttpHelper.getAsync(Constants.GET_UID, null, callback) + } + + fun getUid(token: String, callback: JsonCallback) { + HttpHelper.getAsync(Constants.GET_UID, token, null, callback) + } + + fun getLimitStatus(callback: JsonCallback) { + HttpHelper.getAsync(Constants.RATE_LIMIT_STATUS, null, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/user/User.java b/app/src/main/java/moe/tlaster/openween/core/api/user/User.java deleted file mode 100644 index 4dd77b5..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/api/user/User.java +++ /dev/null @@ -1,26 +0,0 @@ -package moe.tlaster.openween.core.api.user; - -import java.util.HashMap; -import java.util.Map; - -import moe.tlaster.openween.core.api.Constants; -import moe.tlaster.openween.core.model.user.UserModel; -import moe.tlaster.openween.common.helpers.HttpHelper; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; - -/** - * Created by Tlaster on 2016/9/9. - */ -public class User { - public static void getUser(long uid, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("uid", String.valueOf(uid)); - HttpHelper.getAsync(Constants.USER_SHOW, param, callback); - } - public static void getUser(String screen_name, JsonCallback callback) { - Map param = new HashMap<>(); - param.put("screen_name", screen_name); - HttpHelper.getAsync(Constants.USER_SHOW, param, callback); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/api/user/User.kt b/app/src/main/java/moe/tlaster/openween/core/api/user/User.kt new file mode 100644 index 0000000..69b734a --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/api/user/User.kt @@ -0,0 +1,26 @@ +package moe.tlaster.openween.core.api.user + +import java.util.HashMap + +import moe.tlaster.openween.core.api.Constants +import moe.tlaster.openween.core.model.user.UserModel +import moe.tlaster.openween.common.helpers.HttpHelper +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback + +/** + * Created by Tlaster on 2016/9/9. + */ +object User { + fun getUser(uid: Long, callback: JsonCallback) { + val param = HashMap() + param.put("uid", uid.toString()) + HttpHelper.getAsync(Constants.USER_SHOW, param, callback) + } + + fun getUser(screen_name: String, callback: JsonCallback) { + val param = HashMap() + param.put("screen_name", screen_name) + HttpHelper.getAsync(Constants.USER_SHOW, param, callback) + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/BaseListModel.java b/app/src/main/java/moe/tlaster/openween/core/model/BaseListModel.java deleted file mode 100644 index 99982c6..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/BaseListModel.java +++ /dev/null @@ -1,39 +0,0 @@ -package moe.tlaster.openween.core.model; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Tlaster on 2016/8/26. - */ -public class BaseListModel { - @SerializedName("previous_cursor") - private String mPreviousCursor; - @SerializedName("next_cursor") - private String mNextCursor; - @SerializedName("total_number") - private int mTotalNumber; - - public String getPreviousCursor() { - return mPreviousCursor; - } - - public void setPreviousCursor(String previousCursor) { - mPreviousCursor = previousCursor; - } - - public String getNextCursor() { - return mNextCursor; - } - - public void setNextCursor(String nextCursor) { - mNextCursor = nextCursor; - } - - public int getTotalNumber() { - return mTotalNumber; - } - - public void setTotalNumber(int totalNumber) { - mTotalNumber = totalNumber; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/BaseListModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/BaseListModel.kt new file mode 100644 index 0000000..771da32 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/BaseListModel.kt @@ -0,0 +1,15 @@ +package moe.tlaster.openween.core.model + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/8/26. + */ +open class BaseListModel { + @SerializedName("previous_cursor") + var previousCursor: String? = null + @SerializedName("next_cursor") + var nextCursor: String? = null + @SerializedName("total_number") + open var totalNumber: Int = 0 +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/BaseModel.java b/app/src/main/java/moe/tlaster/openween/core/model/BaseModel.java deleted file mode 100644 index 2dc154f..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/BaseModel.java +++ /dev/null @@ -1,113 +0,0 @@ -package moe.tlaster.openween.core.model; - -import android.os.Parcelable; - -import com.chad.library.adapter.base.entity.MultiItemEntity; -import com.google.gson.annotations.SerializedName; - -import org.ocpsoft.prettytime.PrettyTime; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - -import moe.tlaster.openween.common.helpers.TimeHelper; -import moe.tlaster.openween.core.model.user.UserModel; - -/** - * Created by Tlaster on 2016/8/26. - */ -public abstract class BaseModel implements MultiItemEntity { - - public static final int MESSAGE = 1; - public static final int COMMENT = 2; - @SerializedName("id") - protected long mID; - @SerializedName("mid") - protected long mMID; - @SerializedName("idstr") - protected String mIDStr; - @SerializedName("created_at") - protected String mCreatedAt; - @SerializedName("text") - protected String mText; - @SerializedName("source") - protected String mSource; - @SerializedName("user") - protected UserModel mUser; - - public long getMID() { - return mMID; - } - - public void setMID(long MID) { - mMID = MID; - } - - public long getID() { - return mID; - } - - public void setID(long ID) { - mID = ID; - } - - public String getIDStr() { - return mIDStr; - } - - public void setIDStr(String IDStr) { - mIDStr = IDStr; - } - - public String getCreatedAt() { - return mCreatedAt; - } - public String getCreatedAtDiffForHuman(){ - try { - return TimeHelper.getmPrettyTime().format(TimeHelper.getmSimpleDateFormat().parse(mCreatedAt)); - } catch (ParseException e) { - e.printStackTrace(); - } - return mCreatedAt; - } - - public Date getCreatedDate(){ - try { - return TimeHelper.getmSimpleDateFormat().parse(mCreatedAt); - } catch (ParseException e) { - return null; - } - } - - public void setCreatedAt(String createdAt) { - mCreatedAt = createdAt; - } - - public String getText() { - return mText; - } - - public void setText(String text) { - mText = text; - } - - public String getSource() { - return mSource; - } - - public void setSource(String source) { - mSource = source; - } - - public UserModel getUser() { - return mUser; - } - - public void setUser(UserModel user) { - mUser = user; - } - - -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/BaseModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/BaseModel.kt new file mode 100644 index 0000000..c55a624 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/BaseModel.kt @@ -0,0 +1,58 @@ +package moe.tlaster.openween.core.model + +import android.os.Parcelable + +import com.chad.library.adapter.base.entity.MultiItemEntity +import com.google.gson.annotations.SerializedName + +import org.ocpsoft.prettytime.PrettyTime + +import java.text.ParseException +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale + +import moe.tlaster.openween.common.helpers.TimeHelper +import moe.tlaster.openween.core.model.user.UserModel + +/** + * Created by Tlaster on 2016/8/26. + */ +abstract class BaseModel { + @SerializedName("id") + var id: Long = 0 + @SerializedName("mid") + var mid: Long = 0 + @SerializedName("idstr") + var idStr: String = "" + @SerializedName("created_at") + var createdAt: String = "" + @SerializedName("text") + var text: String = "" + @SerializedName("source") + var source: String = "" + @SerializedName("user") + var user: UserModel? = null + val createdAtDiffForHuman: String + get() { + try { + return TimeHelper.prettyTime.format(TimeHelper.simpleDateFormat.parse(createdAt)) + } catch (e: ParseException) { + e.printStackTrace() + } + + return createdAt + } + + val createdDate: Date? + get() { + try { + return TimeHelper.simpleDateFormat.parse(createdAt) + } catch (e: ParseException) { + return null + } + + } + + +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/EmotionModel.java b/app/src/main/java/moe/tlaster/openween/core/model/EmotionModel.java deleted file mode 100644 index af338d0..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/EmotionModel.java +++ /dev/null @@ -1,99 +0,0 @@ -package moe.tlaster.openween.core.model; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Tlaster on 2016/8/26. - */ -public class EmotionModel { - @SerializedName("phrase") - private String mPhrase; - @SerializedName("type") - private String mType; - @SerializedName("url") - private String mUrl; - @SerializedName("hot") - private boolean mHot; - @SerializedName("common") - private boolean mCommon; - @SerializedName("category") - private String mCategory; - @SerializedName("icon") - private String mIcon; - @SerializedName("value") - private String mValue; - @SerializedName("picid") - private String mPicID; - - public String getPhrase() { - return mPhrase; - } - - public void setPhrase(String phrase) { - mPhrase = phrase; - } - - public String getType() { - return mType; - } - - public void setType(String type) { - mType = type; - } - - public String getUrl() { - return mUrl; - } - - public void setUrl(String url) { - mUrl = url; - } - - public boolean isHot() { - return mHot; - } - - public void setHot(boolean hot) { - mHot = hot; - } - - public boolean isCommon() { - return mCommon; - } - - public void setCommon(boolean common) { - mCommon = common; - } - - public String getCategory() { - return mCategory; - } - - public void setCategory(String category) { - mCategory = category; - } - - public String getIcon() { - return mIcon; - } - - public void setIcon(String icon) { - mIcon = icon; - } - - public String getValue() { - return mValue; - } - - public void setValue(String value) { - mValue = value; - } - - public String getPicID() { - return mPicID; - } - - public void setPicID(String picID) { - mPicID = picID; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/EmotionModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/EmotionModel.kt new file mode 100644 index 0000000..c46d861 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/EmotionModel.kt @@ -0,0 +1,27 @@ +package moe.tlaster.openween.core.model + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/8/26. + */ +class EmotionModel { + @SerializedName("phrase") + var phrase: String? = null + @SerializedName("type") + var type: String? = null + @SerializedName("url") + var url: String? = null + @SerializedName("hot") + var isHot: Boolean = false + @SerializedName("common") + var isCommon: Boolean = false + @SerializedName("category") + var category: String? = null + @SerializedName("icon") + var icon: String? = null + @SerializedName("value") + var value: String? = null + @SerializedName("picid") + var picID: String? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/GeoModel.java b/app/src/main/java/moe/tlaster/openween/core/model/GeoModel.java deleted file mode 100644 index ea983f6..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/GeoModel.java +++ /dev/null @@ -1,147 +0,0 @@ -package moe.tlaster.openween.core.model; - -import android.os.Parcel; -import android.os.Parcelable; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Tlaster on 2016/8/26. - */ -public class GeoModel implements Parcelable { - @SerializedName("longitude") - private String mLongitude; - @SerializedName("latitude") - private String mLatitude; - @SerializedName("city") - private String mCity; - @SerializedName("province") - private String mProvince; - @SerializedName("city_name") - private String mCityName; - @SerializedName("province_name") - private String mProvinceName; - @SerializedName("address") - private String mAddress; - @SerializedName("pinyin") - private String mPinyin; - @SerializedName("more") - private String mMore; - - public String getLongitude() { - return mLongitude; - } - - public void setLongitude(String longitude) { - mLongitude = longitude; - } - - public String getLatitude() { - return mLatitude; - } - - public void setLatitude(String latitude) { - mLatitude = latitude; - } - - public String getCity() { - return mCity; - } - - public void setCity(String city) { - mCity = city; - } - - public String getProvince() { - return mProvince; - } - - public void setProvince(String province) { - mProvince = province; - } - - public String getCityName() { - return mCityName; - } - - public void setCityName(String cityName) { - mCityName = cityName; - } - - public String getProvinceName() { - return mProvinceName; - } - - public void setProvinceName(String provinceName) { - mProvinceName = provinceName; - } - - public String getAddress() { - return mAddress; - } - - public void setAddress(String address) { - mAddress = address; - } - - public String getPinyin() { - return mPinyin; - } - - public void setPinyin(String pinyin) { - mPinyin = pinyin; - } - - public String getMore() { - return mMore; - } - - public void setMore(String more) { - mMore = more; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(this.mLongitude); - dest.writeString(this.mLatitude); - dest.writeString(this.mCity); - dest.writeString(this.mProvince); - dest.writeString(this.mCityName); - dest.writeString(this.mProvinceName); - dest.writeString(this.mAddress); - dest.writeString(this.mPinyin); - dest.writeString(this.mMore); - } - - public GeoModel() { - } - - protected GeoModel(Parcel in) { - this.mLongitude = in.readString(); - this.mLatitude = in.readString(); - this.mCity = in.readString(); - this.mProvince = in.readString(); - this.mCityName = in.readString(); - this.mProvinceName = in.readString(); - this.mAddress = in.readString(); - this.mPinyin = in.readString(); - this.mMore = in.readString(); - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public GeoModel createFromParcel(Parcel source) { - return new GeoModel(source); - } - - @Override - public GeoModel[] newArray(int size) { - return new GeoModel[size]; - } - }; -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/GeoModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/GeoModel.kt new file mode 100644 index 0000000..86fe017 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/GeoModel.kt @@ -0,0 +1,74 @@ +package moe.tlaster.openween.core.model + +import android.os.Parcel +import android.os.Parcelable + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/8/26. + */ +class GeoModel : Parcelable { + @SerializedName("longitude") + var longitude: String? = null + @SerializedName("latitude") + var latitude: String? = null + @SerializedName("city") + var city: String? = null + @SerializedName("province") + var province: String? = null + @SerializedName("city_name") + var cityName: String? = null + @SerializedName("province_name") + var provinceName: String? = null + @SerializedName("address") + var address: String? = null + @SerializedName("pinyin") + var pinyin: String? = null + @SerializedName("more") + var more: String? = null + + override fun describeContents(): Int { + return 0 + } + + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeString(this.longitude) + dest.writeString(this.latitude) + dest.writeString(this.city) + dest.writeString(this.province) + dest.writeString(this.cityName) + dest.writeString(this.provinceName) + dest.writeString(this.address) + dest.writeString(this.pinyin) + dest.writeString(this.more) + } + + constructor() { + } + + protected constructor(`in`: Parcel) { + this.longitude = `in`.readString() + this.latitude = `in`.readString() + this.city = `in`.readString() + this.province = `in`.readString() + this.cityName = `in`.readString() + this.provinceName = `in`.readString() + this.address = `in`.readString() + this.pinyin = `in`.readString() + this.more = `in`.readString() + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): GeoModel { + return GeoModel(source) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/LimitStatusModel.java b/app/src/main/java/moe/tlaster/openween/core/model/LimitStatusModel.java deleted file mode 100644 index 4f91c29..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/LimitStatusModel.java +++ /dev/null @@ -1,99 +0,0 @@ -package moe.tlaster.openween.core.model; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Tlaster on 2016/8/26. - */ -public class LimitStatusModel { - @SerializedName("ip_limit") - private long mIpLimit; - @SerializedName("limit_time_unit") - private String mLimitTimeUnit; - @SerializedName("remaining_ip_hits") - private long mRemainingIpHits; - @SerializedName("remaining_user_hits") - private int mRemainingUserHits; - @SerializedName("reset_time") - private String mResetTimeValue; - @SerializedName("reset_time_in_seconds") - private long mResetTimeInSeconds; - @SerializedName("user_limit") - private int mUserLimit; - @SerializedName("error") - private String mError; - @SerializedName("error_code") - private String mErrorCode; - - public String getError() { - return mError; - } - - public void setError(String error) { - mError = error; - } - - public String getErrorCode() { - return mErrorCode; - } - - public void setErrorCode(String errorCode) { - mErrorCode = errorCode; - } - - public long getIpLimit() { - return mIpLimit; - } - - public void setIpLimit(long ipLimit) { - mIpLimit = ipLimit; - } - - public String getLimitTimeUnit() { - return mLimitTimeUnit; - } - - public void setLimitTimeUnit(String limitTimeUnit) { - mLimitTimeUnit = limitTimeUnit; - } - - public long getRemainingIpHits() { - return mRemainingIpHits; - } - - public void setRemainingIpHits(long remainingIpHits) { - mRemainingIpHits = remainingIpHits; - } - - public int getRemainingUserHits() { - return mRemainingUserHits; - } - - public void setRemainingUserHits(int remainingUserHits) { - mRemainingUserHits = remainingUserHits; - } - - public String getResetTimeValue() { - return mResetTimeValue; - } - - public void setResetTimeValue(String resetTimeValue) { - mResetTimeValue = resetTimeValue; - } - - public long getResetTimeInSeconds() { - return mResetTimeInSeconds; - } - - public void setResetTimeInSeconds(long resetTimeInSeconds) { - mResetTimeInSeconds = resetTimeInSeconds; - } - - public int getUserLimit() { - return mUserLimit; - } - - public void setUserLimit(int userLimit) { - mUserLimit = userLimit; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/LimitStatusModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/LimitStatusModel.kt new file mode 100644 index 0000000..5bac136 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/LimitStatusModel.kt @@ -0,0 +1,27 @@ +package moe.tlaster.openween.core.model + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/8/26. + */ +class LimitStatusModel { + @SerializedName("ip_limit") + var ipLimit: Long = 0 + @SerializedName("limit_time_unit") + var limitTimeUnit: String? = null + @SerializedName("remaining_ip_hits") + var remainingIpHits: Long = 0 + @SerializedName("remaining_user_hits") + var remainingUserHits: Int = 0 + @SerializedName("reset_time") + var resetTimeValue: String? = null + @SerializedName("reset_time_in_seconds") + var resetTimeInSeconds: Long = 0 + @SerializedName("user_limit") + var userLimit: Int = 0 + @SerializedName("error") + var error: String? = null + @SerializedName("error_code") + var errorCode: String? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/UnreadModel.java b/app/src/main/java/moe/tlaster/openween/core/model/UnreadModel.java deleted file mode 100644 index 039af00..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/UnreadModel.java +++ /dev/null @@ -1,158 +0,0 @@ -package moe.tlaster.openween.core.model; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Tlaster on 2016/8/26. - */ -public class UnreadModel { - @SerializedName("status") - private int mStatus = 0; - @SerializedName("follower") - private int mFollower = 0; - @SerializedName("cmt") - private int mCmt = 0; - @SerializedName("dm") - private int mDm = 0; - @SerializedName("mention_status") - private int mMentionStatus = 0; - @SerializedName("mention_cmt") - private int mMentionCmt = 0; - @SerializedName("group") - private int mGroup = 0; - @SerializedName("private_group") - private int mPrivateGroup = 0; - @SerializedName("notice") - private int mNotice = 0; - @SerializedName("invite") - private int mInvite = 0; - @SerializedName("badge") - private int mBadge = 0; - @SerializedName("photo") - private int mPhoto = 0; - @SerializedName("msgbox") - private int mMsgBox = 0; - - public int getStatus() { - return mStatus; - } - - public void setStatus(int status) { - mStatus = status; - } - - public int getFollower() { - return mFollower; - } - - public void setFollower(int follower) { - mFollower = follower; - } - - public int getCmt() { - return mCmt; - } - - public void setCmt(int cmt) { - mCmt = cmt; - } - - public int getDm() { - return mDm; - } - - public void setDm(int dm) { - mDm = dm; - } - - public int getMentionStatus() { - return mMentionStatus; - } - - public void setMentionStatus(int mentionStatus) { - mMentionStatus = mentionStatus; - } - - public int getMentionCmt() { - return mMentionCmt; - } - - public void setMentionCmt(int mentionCmt) { - mMentionCmt = mentionCmt; - } - - public int getGroup() { - return mGroup; - } - - public void setGroup(int group) { - mGroup = group; - } - - public int getPrivateGroup() { - return mPrivateGroup; - } - - public void setPrivateGroup(int privateGroup) { - mPrivateGroup = privateGroup; - } - - public int getNotice() { - return mNotice; - } - - public void setNotice(int notice) { - mNotice = notice; - } - - public int getInvite() { - return mInvite; - } - - public void setInvite(int invite) { - mInvite = invite; - } - - public int getBadge() { - return mBadge; - } - - public void setBadge(int badge) { - mBadge = badge; - } - - public int getPhoto() { - return mPhoto; - } - - public void setPhoto(int photo) { - mPhoto = photo; - } - - public int getMsgBox() { - return mMsgBox; - } - - public void setMsgBox(int msgBox) { - mMsgBox = msgBox; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof UnreadModel)) return false; - UnreadModel model = (UnreadModel) obj; - return model.getStatus() == getStatus() && - model.getFollower() == getFollower() && - model.getCmt() == getCmt() && - model.getDm() == getDm() && - model.getMentionStatus() == getMentionStatus() && - model.getMentionCmt() == getMentionCmt() && - model.getGroup() == getGroup() && - model.getPrivateGroup() == getPrivateGroup() && - model.getNotice() == getNotice() && - model.getInvite() == getInvite() && - model.getBadge() == getBadge() && - model.getPhoto() == getPhoto() && - model.getMsgBox() == getMsgBox(); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/UnreadModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/UnreadModel.kt new file mode 100644 index 0000000..127a12d --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/UnreadModel.kt @@ -0,0 +1,52 @@ +package moe.tlaster.openween.core.model + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/8/26. + */ +class UnreadModel { + @SerializedName("status") + var status = 0 + @SerializedName("follower") + var follower = 0 + @SerializedName("cmt") + var cmt = 0 + @SerializedName("dm") + var dm = 0 + @SerializedName("mention_status") + var mentionStatus = 0 + @SerializedName("mention_cmt") + var mentionCmt = 0 + @SerializedName("group") + var group = 0 + @SerializedName("private_group") + var privateGroup = 0 + @SerializedName("notice") + var notice = 0 + @SerializedName("invite") + var invite = 0 + @SerializedName("badge") + var badge = 0 + @SerializedName("photo") + var photo = 0 + @SerializedName("msgbox") + var msgBox = 0 + + override fun equals(obj: Any?): Boolean { + if (obj !is UnreadModel) return false + return obj.status == status && + obj.follower == follower && + obj.cmt == cmt && + obj.dm == dm && + obj.mentionStatus == mentionStatus && + obj.mentionCmt == mentionCmt && + obj.group == group && + obj.privateGroup == privateGroup && + obj.notice == notice && + obj.invite == invite && + obj.badge == badge && + obj.photo == photo && + obj.msgBox == msgBox + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/Url/AnnotationModel.java b/app/src/main/java/moe/tlaster/openween/core/model/Url/AnnotationModel.java deleted file mode 100644 index 5c7ec1b..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/Url/AnnotationModel.java +++ /dev/null @@ -1,19 +0,0 @@ -package moe.tlaster.openween.core.model.url; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class AnnotationModel { - @SerializedName("object") - private ObjectModel mItem; - - public ObjectModel getItem() { - return mItem; - } - - public void setItem(ObjectModel item) { - mItem = item; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/Url/ObjectModel.java b/app/src/main/java/moe/tlaster/openween/core/model/Url/ObjectModel.java deleted file mode 100644 index 845420b..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/Url/ObjectModel.java +++ /dev/null @@ -1,79 +0,0 @@ -package moe.tlaster.openween.core.model.url; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class ObjectModel { - @SerializedName("url") - private String mUrl; - @SerializedName("display_name") - private String mDisplayName; - @SerializedName("pic_ids") - private String[] mPicIds; - @SerializedName("object_type") - private String mObjectType; - @SerializedName("object") - private Object mUrlObject; - @SerializedName("original_url") - private String mOriginalUrl; - @SerializedName("stream") - private StreamModel mStream; - - public String getUrl() { - return mUrl; - } - - public void setUrl(String url) { - mUrl = url; - } - - public String getDisplayName() { - return mDisplayName; - } - - public void setDisplayName(String displayName) { - mDisplayName = displayName; - } - - public String[] getPicIds() { - return mPicIds; - } - - public void setPicIds(String[] picIds) { - mPicIds = picIds; - } - - public String getObjectType() { - return mObjectType; - } - - public void setObjectType(String objectType) { - mObjectType = objectType; - } - - public Object getUrlObject() { - return mUrlObject; - } - - public void setUrlObject(Object urlObject) { - mUrlObject = urlObject; - } - - public String getOriginalUrl() { - return mOriginalUrl; - } - - public void setOriginalUrl(String originalUrl) { - mOriginalUrl = originalUrl; - } - - public StreamModel getStream() { - return mStream; - } - - public void setStream(StreamModel stream) { - mStream = stream; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/Url/StreamModel.java b/app/src/main/java/moe/tlaster/openween/core/model/Url/StreamModel.java deleted file mode 100644 index 98c5c55..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/Url/StreamModel.java +++ /dev/null @@ -1,19 +0,0 @@ -package moe.tlaster.openween.core.model.url; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class StreamModel { - @SerializedName("url") - private String mUrl; - - public String getUrl() { - return mUrl; - } - - public void setUrl(String url) { - mUrl = url; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/Url/UrlInfoListModel.java b/app/src/main/java/moe/tlaster/openween/core/model/Url/UrlInfoListModel.java deleted file mode 100644 index 219b590..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/Url/UrlInfoListModel.java +++ /dev/null @@ -1,22 +0,0 @@ -package moe.tlaster.openween.core.model.url; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class UrlInfoListModel { - public List getUrls() { - return mUrls; - } - - public void setUrls(List urls) { - mUrls = urls; - } - - @SerializedName("urls") - private List mUrls; - -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/Url/UrlInfoModel.java b/app/src/main/java/moe/tlaster/openween/core/model/Url/UrlInfoModel.java deleted file mode 100644 index 649fb52..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/Url/UrlInfoModel.java +++ /dev/null @@ -1,92 +0,0 @@ -package moe.tlaster.openween.core.model.url; - - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class UrlInfoModel { - @SerializedName("result") - private boolean mResult; - @SerializedName("last_modified") - private long mLastModified; - @SerializedName("title") - private String mTitle; - @SerializedName("description") - private String mDescription; - @SerializedName("url_short") - private String mUrlShort; - @SerializedName("url_long") - private String mUrlLong; - @SerializedName("annotations") - private List mAnnotations; - @SerializedName("type") - private int mType; - - public boolean isResult() { - return mResult; - } - - public void setResult(boolean result) { - mResult = result; - } - - public long getLastModified() { - return mLastModified; - } - - public void setLastModified(long lastModified) { - mLastModified = lastModified; - } - - public String getTitle() { - return mTitle; - } - - public void setTitle(String title) { - mTitle = title; - } - - public String getDescription() { - return mDescription; - } - - public void setDescription(String description) { - mDescription = description; - } - - public String getUrlShort() { - return mUrlShort; - } - - public void setUrlShort(String urlShort) { - mUrlShort = urlShort; - } - - public String getUrlLong() { - return mUrlLong; - } - - public void setUrlLong(String urlLong) { - mUrlLong = urlLong; - } - - public List getAnnotations() { - return mAnnotations; - } - - public void setAnnotations(List annotations) { - mAnnotations = annotations; - } - - public int getType() { - return mType; - } - - public void setType(int type) { - mType = type; - } -} \ No newline at end of file diff --git a/app/src/main/java/moe/tlaster/openween/core/model/block/BlockListModel.java b/app/src/main/java/moe/tlaster/openween/core/model/block/BlockListModel.java deleted file mode 100644 index d16d5fd..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/block/BlockListModel.java +++ /dev/null @@ -1,21 +0,0 @@ -package moe.tlaster.openween.core.model.block; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class BlockListModel { - @SerializedName("users") - private List mUsers; - - public List getUsers() { - return mUsers; - } - - public void setUsers(List users) { - mUsers = users; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/block/BlockListModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/block/BlockListModel.kt new file mode 100644 index 0000000..55862ce --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/block/BlockListModel.kt @@ -0,0 +1,11 @@ +package moe.tlaster.openween.core.model.block + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +class BlockListModel { + @SerializedName("users") + var users: List? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/block/BlockModel.java b/app/src/main/java/moe/tlaster/openween/core/model/block/BlockModel.java deleted file mode 100644 index 863dd3a..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/block/BlockModel.java +++ /dev/null @@ -1,32 +0,0 @@ -package moe.tlaster.openween.core.model.block; - -import com.google.gson.annotations.SerializedName; - -import moe.tlaster.openween.core.model.user.UserModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class BlockModel { - @SerializedName("user") - private UserModel mUser; - @SerializedName("created_at") - private String mCreatedAt; - - public String getCreatedAt() { - return mCreatedAt; - } - - public void setCreatedAt(String createdAt) { - mCreatedAt = createdAt; - } - - public UserModel getUser() { - return mUser; - } - - public void setUser(UserModel user) { - mUser = user; - } - -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/block/BlockModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/block/BlockModel.kt new file mode 100644 index 0000000..794b4a3 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/block/BlockModel.kt @@ -0,0 +1,16 @@ +package moe.tlaster.openween.core.model.block + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.user.UserModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class BlockModel { + @SerializedName("user") + var user: UserModel? = null + @SerializedName("created_at") + var createdAt: String? = null + +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/comment/CommentListModel.java b/app/src/main/java/moe/tlaster/openween/core/model/comment/CommentListModel.java deleted file mode 100644 index 2e64bf9..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/comment/CommentListModel.java +++ /dev/null @@ -1,23 +0,0 @@ -package moe.tlaster.openween.core.model.comment; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -import moe.tlaster.openween.core.model.BaseListModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class CommentListModel extends BaseListModel { - @SerializedName("comments") - private List mComments; - - public List getComments() { - return mComments; - } - - public void setComments(List comments) { - mComments = comments; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/comment/CommentListModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/comment/CommentListModel.kt new file mode 100644 index 0000000..bd3940d --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/comment/CommentListModel.kt @@ -0,0 +1,13 @@ +package moe.tlaster.openween.core.model.comment + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.BaseListModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class CommentListModel : BaseListModel() { + @SerializedName("comments") + var comments: List? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/comment/CommentModel.java b/app/src/main/java/moe/tlaster/openween/core/model/comment/CommentModel.java deleted file mode 100644 index b5ba12d..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/comment/CommentModel.java +++ /dev/null @@ -1,57 +0,0 @@ -package moe.tlaster.openween.core.model.comment; - -import com.google.gson.annotations.SerializedName; - -import moe.tlaster.openween.core.model.BaseModel; -import moe.tlaster.openween.core.model.status.MessageModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class CommentModel extends BaseModel { - @SerializedName("source_allowclick") - private int mSourceAllowClick; - @SerializedName("source_type") - private int mSourceType; - @SerializedName("status") - private MessageModel mStatus; - @SerializedName("reply_comment") - private CommentModel mReplyComment; - - public int getSourceAllowClick() { - return mSourceAllowClick; - } - - public void setSourceAllowClick(int sourceAllowClick) { - mSourceAllowClick = sourceAllowClick; - } - - public int getSourceType() { - return mSourceType; - } - - public void setSourceType(int sourceType) { - mSourceType = sourceType; - } - - public MessageModel getStatus() { - return mStatus; - } - - public void setStatus(MessageModel status) { - mStatus = status; - } - - public CommentModel getReplyComment() { - return mReplyComment; - } - - public void setReplyComment(CommentModel replyComment) { - mReplyComment = replyComment; - } - - @Override - public int getItemType() { - return COMMENT; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/comment/CommentModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/comment/CommentModel.kt new file mode 100644 index 0000000..1da5b36 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/comment/CommentModel.kt @@ -0,0 +1,20 @@ +package moe.tlaster.openween.core.model.comment + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.BaseModel +import moe.tlaster.openween.core.model.status.MessageModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class CommentModel : BaseModel() { + @SerializedName("source_allowclick") + var sourceAllowClick: Int = 0 + @SerializedName("source_type") + var sourceType: Int = 0 + @SerializedName("status") + var status: MessageModel? = null + @SerializedName("reply_comment") + var replyComment: CommentModel? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageListModel.java b/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageListModel.java deleted file mode 100644 index bdf592c..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageListModel.java +++ /dev/null @@ -1,24 +0,0 @@ -package moe.tlaster.openween.core.model.directmessage; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -import moe.tlaster.openween.core.model.BaseListModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class DirectMessageListModel extends BaseListModel { - @SerializedName("direct_messages") - private List mDirectMessages; - - public List getDirectMessages() { - return mDirectMessages; - } - - public void setDirectMessages(List directMessages) { - mDirectMessages = directMessages; - } - -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageListModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageListModel.kt new file mode 100644 index 0000000..ef10e30 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageListModel.kt @@ -0,0 +1,14 @@ +package moe.tlaster.openween.core.model.directmessage + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.BaseListModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class DirectMessageListModel : BaseListModel() { + @SerializedName("direct_messages") + var directMessages: List? = null + +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageModel.java b/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageModel.java deleted file mode 100644 index 9ff2064..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageModel.java +++ /dev/null @@ -1,121 +0,0 @@ -package moe.tlaster.openween.core.model.directmessage; - -import com.google.gson.annotations.SerializedName; - -import moe.tlaster.openween.core.model.user.UserModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class DirectMessageModel { - @SerializedName("id") - private long mID; - @SerializedName("idstr") - private String mIDStr; - @SerializedName("created_at") - private String mCreatedAt; - @SerializedName("text") - private String mText; - @SerializedName("sender_id") - private long mSenderID; - @SerializedName("recipient_id") - private long mRecipientID; - @SerializedName("recipient") - private UserModel mRecipient; - @SerializedName("sender") - private UserModel mSender; - @SerializedName("sender_screen_name") - private String mSenderScreenName; - @SerializedName("recipient_screen_name") - private String mRecipientScreenName; - @SerializedName("att_ids") - private long[] AttIDs = { 0, 0 }; - - public long getID() { - return mID; - } - - public void setID(long ID) { - mID = ID; - } - - public String getIDStr() { - return mIDStr; - } - - public void setIDStr(String IDStr) { - mIDStr = IDStr; - } - - public String getCreatedAt() { - return mCreatedAt; - } - - public void setCreatedAt(String createdAt) { - mCreatedAt = createdAt; - } - - public String getText() { - return mText; - } - - public void setText(String text) { - mText = text; - } - - public long getSenderID() { - return mSenderID; - } - - public void setSenderID(long senderID) { - mSenderID = senderID; - } - - public long getRecipientID() { - return mRecipientID; - } - - public void setRecipientID(long recipientID) { - mRecipientID = recipientID; - } - - public UserModel getRecipient() { - return mRecipient; - } - - public void setRecipient(UserModel recipient) { - mRecipient = recipient; - } - - public UserModel getSender() { - return mSender; - } - - public void setSender(UserModel sender) { - mSender = sender; - } - - public String getSenderScreenName() { - return mSenderScreenName; - } - - public void setSenderScreenName(String senderScreenName) { - mSenderScreenName = senderScreenName; - } - - public String getRecipientScreenName() { - return mRecipientScreenName; - } - - public void setRecipientScreenName(String recipientScreenName) { - mRecipientScreenName = recipientScreenName; - } - - public long[] getAttIDs() { - return AttIDs; - } - - public void setAttIDs(long[] attIDs) { - AttIDs = attIDs; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageModel.kt new file mode 100644 index 0000000..81631f4 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageModel.kt @@ -0,0 +1,33 @@ +package moe.tlaster.openween.core.model.directmessage + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.user.UserModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class DirectMessageModel { + @SerializedName("id") + var id: Long = 0 + @SerializedName("idstr") + var idStr: String? = null + @SerializedName("created_at") + var createdAt: String? = null + @SerializedName("text") + var text: String? = null + @SerializedName("sender_id") + var senderID: Long = 0 + @SerializedName("recipient_id") + var recipientID: Long = 0 + @SerializedName("recipient") + var recipient: UserModel? = null + @SerializedName("sender") + var sender: UserModel? = null + @SerializedName("sender_screen_name") + var senderScreenName: String? = null + @SerializedName("recipient_screen_name") + var recipientScreenName: String? = null + @SerializedName("att_ids") + var attIDs = longArrayOf(0, 0) +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageUserListModel.java b/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageUserListModel.java deleted file mode 100644 index 0fb7e18..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageUserListModel.java +++ /dev/null @@ -1,35 +0,0 @@ -package moe.tlaster.openween.core.model.directmessage; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -import moe.tlaster.openween.core.model.BaseListModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class DirectMessageUserListModel extends BaseListModel { - @SerializedName("user_list") - private List mUserList; - @SerializedName("totalNumber") - private int mTotalNumber; - - public List getUserList() { - return mUserList; - } - - public void setUserList(List userList) { - mUserList = userList; - } - - @Override - public int getTotalNumber() { - return mTotalNumber; - } - - @Override - public void setTotalNumber(int totalNumber) { - mTotalNumber = totalNumber; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageUserListModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageUserListModel.kt new file mode 100644 index 0000000..ca94058 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageUserListModel.kt @@ -0,0 +1,15 @@ +package moe.tlaster.openween.core.model.directmessage + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.BaseListModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class DirectMessageUserListModel : BaseListModel() { + @SerializedName("user_list") + var userList: List? = null + @SerializedName("totalNumber") + override var totalNumber: Int = 0 +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageUserModel.java b/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageUserModel.java deleted file mode 100644 index b84b7d2..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageUserModel.java +++ /dev/null @@ -1,31 +0,0 @@ -package moe.tlaster.openween.core.model.directmessage; - -import com.google.gson.annotations.SerializedName; - -import moe.tlaster.openween.core.model.user.UserModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class DirectMessageUserModel { - @SerializedName("user") - private UserModel mUser; - @SerializedName("direct_message") - private DirectMessageModel mDirectMessage; - - public UserModel getUser() { - return mUser; - } - - public void setUser(UserModel user) { - mUser = user; - } - - public DirectMessageModel getDirectMessage() { - return mDirectMessage; - } - - public void setDirectMessage(DirectMessageModel directMessage) { - mDirectMessage = directMessage; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageUserModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageUserModel.kt new file mode 100644 index 0000000..7d06ff9 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/directmessage/DirectMessageUserModel.kt @@ -0,0 +1,15 @@ +package moe.tlaster.openween.core.model.directmessage + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.user.UserModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class DirectMessageUserModel { + @SerializedName("user") + var user: UserModel? = null + @SerializedName("direct_message") + var directMessage: DirectMessageModel? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorListModel.java b/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorListModel.java deleted file mode 100644 index a6bf586..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorListModel.java +++ /dev/null @@ -1,31 +0,0 @@ -package moe.tlaster.openween.core.model.favor; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class FavorListModel { - @SerializedName("favorites") - private List mFavorites; - @SerializedName("total_number") - private int mTotalNumber; - - public List getFavorites() { - return mFavorites; - } - - public void setFavorites(List favorites) { - mFavorites = favorites; - } - - public int getTotalNumber() { - return mTotalNumber; - } - - public void setTotalNumber(int totalNumber) { - mTotalNumber = totalNumber; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorListModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorListModel.kt new file mode 100644 index 0000000..2e80273 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorListModel.kt @@ -0,0 +1,13 @@ +package moe.tlaster.openween.core.model.favor + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +class FavorListModel { + @SerializedName("favorites") + var favorites: List? = null + @SerializedName("total_number") + var totalNumber: Int = 0 +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorModel.java b/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorModel.java deleted file mode 100644 index fcb0e38..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorModel.java +++ /dev/null @@ -1,43 +0,0 @@ -package moe.tlaster.openween.core.model.favor; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -import moe.tlaster.openween.core.model.status.MessageModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class FavorModel { - @SerializedName("status") - private MessageModel mStatus; - @SerializedName("favorited_time") - private String mFavoritedTime; - @SerializedName("tags") - private List mTags; - - public MessageModel getStatus() { - return mStatus; - } - - public void setStatus(MessageModel status) { - mStatus = status; - } - - public String getFavoritedTime() { - return mFavoritedTime; - } - - public void setFavoritedTime(String favoritedTime) { - mFavoritedTime = favoritedTime; - } - - public List getTags() { - return mTags; - } - - public void setTags(List tags) { - mTags = tags; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorModel.kt new file mode 100644 index 0000000..261fc90 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorModel.kt @@ -0,0 +1,17 @@ +package moe.tlaster.openween.core.model.favor + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.status.MessageModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class FavorModel { + @SerializedName("status") + var status: MessageModel? = null + @SerializedName("favorited_time") + var favoritedTime: String? = null + @SerializedName("tags") + var tags: List? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorTagListModel.java b/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorTagListModel.java deleted file mode 100644 index fc23e25..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorTagListModel.java +++ /dev/null @@ -1,31 +0,0 @@ -package moe.tlaster.openween.core.model.favor; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class FavorTagListModel { - @SerializedName("tags") - private List mTags; - @SerializedName("total_number") - private int mTotalNumber; - - public List getTags() { - return mTags; - } - - public void setTags(List tags) { - mTags = tags; - } - - public int getTotalNumber() { - return mTotalNumber; - } - - public void setTotalNumber(int totalNumber) { - mTotalNumber = totalNumber; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorTagListModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorTagListModel.kt new file mode 100644 index 0000000..5073a90 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorTagListModel.kt @@ -0,0 +1,13 @@ +package moe.tlaster.openween.core.model.favor + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +class FavorTagListModel { + @SerializedName("tags") + var tags: List? = null + @SerializedName("total_number") + var totalNumber: Int = 0 +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorTagModel.java b/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorTagModel.java deleted file mode 100644 index bc710ed..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorTagModel.java +++ /dev/null @@ -1,29 +0,0 @@ -package moe.tlaster.openween.core.model.favor; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class FavorTagModel { - @SerializedName("id") - private long mID; - @SerializedName("tag") - private String mTag; - - public long getID() { - return mID; - } - - public void setID(long ID) { - mID = ID; - } - - public String getTag() { - return mTag; - } - - public void setTag(String tag) { - mTag = tag; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorTagModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorTagModel.kt new file mode 100644 index 0000000..3dcaaf3 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/favor/FavorTagModel.kt @@ -0,0 +1,13 @@ +package moe.tlaster.openween.core.model.favor + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +class FavorTagModel { + @SerializedName("id") + var id: Long = 0 + @SerializedName("tag") + var tag: String? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/GroupListModel.java b/app/src/main/java/moe/tlaster/openween/core/model/status/GroupListModel.java deleted file mode 100644 index 0c4df24..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/status/GroupListModel.java +++ /dev/null @@ -1,23 +0,0 @@ -package moe.tlaster.openween.core.model.status; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -import moe.tlaster.openween.core.model.BaseListModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class GroupListModel extends BaseListModel { - @SerializedName("lists") - private List mLists; - - public List getLists() { - return mLists; - } - - public void setLists(List lists) { - mLists = lists; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/GroupListModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/status/GroupListModel.kt new file mode 100644 index 0000000..8272072 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/status/GroupListModel.kt @@ -0,0 +1,13 @@ +package moe.tlaster.openween.core.model.status + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.BaseListModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class GroupListModel : BaseListModel() { + @SerializedName("lists") + var lists: List? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/GroupModel.java b/app/src/main/java/moe/tlaster/openween/core/model/status/GroupModel.java deleted file mode 100644 index 3bf961c..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/status/GroupModel.java +++ /dev/null @@ -1,39 +0,0 @@ -package moe.tlaster.openween.core.model.status; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class GroupModel { - @SerializedName("id") - private long mID; - @SerializedName("idstr") - private String mIDStr; - @SerializedName("name") - private String mName; - - public long getID() { - return mID; - } - - public void setID(long ID) { - mID = ID; - } - - public String getIDStr() { - return mIDStr; - } - - public void setIDStr(String IDStr) { - mIDStr = IDStr; - } - - public String getName() { - return mName; - } - - public void setName(String name) { - mName = name; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/GroupModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/status/GroupModel.kt new file mode 100644 index 0000000..cdce887 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/status/GroupModel.kt @@ -0,0 +1,15 @@ +package moe.tlaster.openween.core.model.status + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +class GroupModel { + @SerializedName("id") + var id: Long = 0 + @SerializedName("idstr") + var idStr: String? = null + @SerializedName("name") + var name: String? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/LongTextModel.java b/app/src/main/java/moe/tlaster/openween/core/model/status/LongTextModel.java deleted file mode 100644 index acaaf09..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/status/LongTextModel.java +++ /dev/null @@ -1,51 +0,0 @@ -package moe.tlaster.openween.core.model.status; - -import android.os.Parcel; -import android.os.Parcelable; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class LongTextModel implements Parcelable { - @SerializedName("longTextContent") - private String mContent; - - public String getContent() { - return mContent; - } - - public void setContent(String content) { - mContent = content; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(this.mContent); - } - - public LongTextModel() { - } - - protected LongTextModel(Parcel in) { - this.mContent = in.readString(); - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public LongTextModel createFromParcel(Parcel source) { - return new LongTextModel(source); - } - - @Override - public LongTextModel[] newArray(int size) { - return new LongTextModel[size]; - } - }; -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/LongTextModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/status/LongTextModel.kt new file mode 100644 index 0000000..75aa7bc --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/status/LongTextModel.kt @@ -0,0 +1,42 @@ +package moe.tlaster.openween.core.model.status + +import android.os.Parcel +import android.os.Parcelable + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +class LongTextModel : Parcelable { + @SerializedName("longTextContent") + var content: String? = null + + override fun describeContents(): Int { + return 0 + } + + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeString(this.content) + } + + constructor() { + } + + protected constructor(`in`: Parcel) { + this.content = `in`.readString() + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): LongTextModel { + return LongTextModel(source) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/MediaModel.java b/app/src/main/java/moe/tlaster/openween/core/model/status/MediaModel.java deleted file mode 100644 index 5c71daf..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/status/MediaModel.java +++ /dev/null @@ -1,36 +0,0 @@ -package moe.tlaster.openween.core.model.status; - -import com.google.gson.Gson; -import com.google.gson.annotations.SerializedName; - -/** - * Created by Asahi on 2016/10/8. - */ - -public class MediaModel { - public MediaModel(String fid) { - mFid = fid; - } - - @SerializedName("bypass") - private String mByPass = "unistore.image"; - @SerializedName("createtype") - private String mCreateType = "localfile"; - @SerializedName("filterName") - private String mFilterName = ""; - @SerializedName("stickerID") - private String mStickerID = ""; - @SerializedName("fid") - private String mFid = ""; - @SerializedName("type") - private String mType = "pic"; - @SerializedName("filterID") - private String mFilterID = ""; - @SerializedName("picStatus") - private int mPicStatus = 0; - - @Override - public String toString() { - return "[" + new Gson().toJson(this) + "]"; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/MediaModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/status/MediaModel.kt new file mode 100644 index 0000000..15fd135 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/status/MediaModel.kt @@ -0,0 +1,35 @@ +package moe.tlaster.openween.core.model.status + +import com.google.gson.Gson +import com.google.gson.annotations.SerializedName + +/** + * Created by Asahi on 2016/10/8. + */ + +class MediaModel(fid: String) { + + @SerializedName("bypass") + private val byPass = "unistore.image" + @SerializedName("createtype") + private val createType = "localfile" + @SerializedName("filterName") + private val filterName = "" + @SerializedName("stickerID") + private val stickerID = "" + @SerializedName("fid") + private var fid = "" + @SerializedName("type") + private val type = "pic" + @SerializedName("filterID") + private val filterID = "" + @SerializedName("picStatus") + private val picStatus = 0 + + init { + this.fid = fid + } + override fun toString(): String { + return "[" + Gson().toJson(this) + "]" + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/MessageListModel.java b/app/src/main/java/moe/tlaster/openween/core/model/status/MessageListModel.java deleted file mode 100644 index 57cd12f..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/status/MessageListModel.java +++ /dev/null @@ -1,23 +0,0 @@ -package moe.tlaster.openween.core.model.status; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -import moe.tlaster.openween.core.model.BaseListModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class MessageListModel extends BaseListModel { - @SerializedName("statuses") - private List mStatuses; - - public List getStatuses() { - return mStatuses; - } - - public void setStatuses(List statuses) { - mStatuses = statuses; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/MessageListModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/status/MessageListModel.kt new file mode 100644 index 0000000..7da4b09 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/status/MessageListModel.kt @@ -0,0 +1,13 @@ +package moe.tlaster.openween.core.model.status + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.BaseListModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class MessageListModel : BaseListModel() { + @SerializedName("statuses") + var statuses: List? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/MessageModel.java b/app/src/main/java/moe/tlaster/openween/core/model/status/MessageModel.java deleted file mode 100644 index fdebd27..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/status/MessageModel.java +++ /dev/null @@ -1,317 +0,0 @@ -package moe.tlaster.openween.core.model.status; - -import android.os.Parcel; -import android.os.Parcelable; - -import com.annimon.stream.Collectors; -import com.annimon.stream.Stream; -import com.google.gson.annotations.SerializedName; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import moe.tlaster.openween.core.model.BaseModel; -import moe.tlaster.openween.core.model.GeoModel; -import moe.tlaster.openween.core.model.user.UserModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class MessageModel extends BaseModel implements Parcelable { - @SerializedName("favorited") - private boolean mFavorited; - @SerializedName("truncated") - private boolean mTruncated; - @SerializedName("liked") - private boolean mLiked; - @SerializedName("in_reply_to_status_id") - private String mInReplyToStatusID; - @SerializedName("in_reply_to_user_id") - private String mInReplyToUserID; - @SerializedName("in_reply_to_screen_name") - private String mInReplyToScreenName; - @SerializedName("thumbnail_pic") - private String mThumbnailPic; - @SerializedName("bmiddle_pic") - private String mBmiddlePic; - @SerializedName("original_pic") - private String mOriginalPic; - @SerializedName("geo") - private GeoModel mGeo; - @SerializedName("retweeted_status") - private MessageModel mRetweetedStatus; - @SerializedName("reposts_count") - private int mRepostsCount; - @SerializedName("comments_count") - private int mCommentsCount; - @SerializedName("attitudes_count") - private int mAttitudesCount; - @SerializedName("mlevel") - private int mMLevel; - @SerializedName("longText") - private LongTextModel mLongText; - @SerializedName("visible") - private WeiboVisibilityModel mVisible; - @SerializedName("pic_urls") - private List mPicUrls; - @SerializedName("pic_infos") - private Map mUserTimelineImage; - - public Map getUserTimelineImage() { - return mUserTimelineImage; - } - - public void setUserTimelineImage(Map userTimelineImage) { - mUserTimelineImage = userTimelineImage; - } - - public boolean isFavorited() { - return mFavorited; - } - - public void setFavorited(boolean favorited) { - mFavorited = favorited; - } - - public boolean isTruncated() { - return mTruncated; - } - - public void setTruncated(boolean truncated) { - mTruncated = truncated; - } - - public boolean isLiked() { - return mLiked; - } - - public void setLiked(boolean liked) { - mLiked = liked; - } - - public String getInReplyToStatusID() { - return mInReplyToStatusID; - } - - public void setInReplyToStatusID(String inReplyToStatusID) { - mInReplyToStatusID = inReplyToStatusID; - } - - public String getInReplyToUserID() { - return mInReplyToUserID; - } - - public void setInReplyToUserID(String inReplyToUserID) { - mInReplyToUserID = inReplyToUserID; - } - - public String getInReplyToScreenName() { - return mInReplyToScreenName; - } - - public void setInReplyToScreenName(String inReplyToScreenName) { - mInReplyToScreenName = inReplyToScreenName; - } - - public String getThumbnailPic() { - return mThumbnailPic; - } - - public void setThumbnailPic(String thumbnailPic) { - mThumbnailPic = thumbnailPic; - } - - public String getBmiddlePic() { - return mBmiddlePic; - } - - public void setBmiddlePic(String bmiddlePic) { - mBmiddlePic = bmiddlePic; - } - - public String getOriginalPic() { - return mOriginalPic; - } - - public void setOriginalPic(String originalPic) { - mOriginalPic = originalPic; - } - - public GeoModel getGeo() { - return mGeo; - } - - public void setGeo(GeoModel geo) { - mGeo = geo; - } - - public MessageModel getRetweetedStatus() { - return mRetweetedStatus; - } - - public void setRetweetedStatus(MessageModel retweetedStatus) { - mRetweetedStatus = retweetedStatus; - } - - public int getRepostsCount() { - return mRepostsCount; - } - - public void setRepostsCount(int repostsCount) { - mRepostsCount = repostsCount; - } - - public int getCommentsCount() { - return mCommentsCount; - } - - public void setCommentsCount(int commentsCount) { - mCommentsCount = commentsCount; - } - - public int getAttitudesCount() { - return mAttitudesCount; - } - - public void setAttitudesCount(int attitudesCount) { - mAttitudesCount = attitudesCount; - } - - public int getMLevel() { - return mMLevel; - } - - public void setMLevel(int MLevel) { - mMLevel = MLevel; - } - - public LongTextModel getLongText() { - return mLongText; - } - - public void setLongText(LongTextModel longText) { - mLongText = longText; - } - - public WeiboVisibilityModel getVisible() { - return mVisible; - } - - public void setVisible(WeiboVisibilityModel visible) { - mVisible = visible; - } - - public List getPicUrls() { - return mPicUrls == null && mUserTimelineImage != null ? - Stream.of(mUserTimelineImage.values()).map(PictureModel::new).collect(Collectors.toCollection(ArrayList::new)) : - mPicUrls; - } - - public void setPicUrls(List picUrls) { - mPicUrls = picUrls; - } - - @Override - public int getItemType() { - return MESSAGE; - } - - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeByte(this.mFavorited ? (byte) 1 : (byte) 0); - dest.writeByte(this.mTruncated ? (byte) 1 : (byte) 0); - dest.writeByte(this.mLiked ? (byte) 1 : (byte) 0); - dest.writeString(this.mInReplyToStatusID); - dest.writeString(this.mInReplyToUserID); - dest.writeString(this.mInReplyToScreenName); - dest.writeString(this.mThumbnailPic); - dest.writeString(this.mBmiddlePic); - dest.writeString(this.mOriginalPic); - dest.writeParcelable(this.mGeo, flags); - dest.writeParcelable(this.mRetweetedStatus, flags); - dest.writeInt(this.mRepostsCount); - dest.writeInt(this.mCommentsCount); - dest.writeInt(this.mAttitudesCount); - dest.writeInt(this.mMLevel); - dest.writeParcelable(this.mLongText, flags); - dest.writeParcelable(this.mVisible, flags); - dest.writeList(this.mPicUrls); - if (mUserTimelineImage != null) { - dest.writeInt(this.mUserTimelineImage.size()); - for (Map.Entry entry : this.mUserTimelineImage.entrySet()) { - dest.writeString(entry.getKey()); - dest.writeParcelable(entry.getValue(), flags); - } - } else { - dest.writeInt(-1); - } - dest.writeLong(this.mID); - dest.writeLong(this.mMID); - dest.writeString(this.mIDStr); - dest.writeString(this.mCreatedAt); - dest.writeString(this.mText); - dest.writeString(this.mSource); - dest.writeParcelable(this.mUser, flags); - } - - public MessageModel() { - } - - protected MessageModel(Parcel in) { - this.mFavorited = in.readByte() != 0; - this.mTruncated = in.readByte() != 0; - this.mLiked = in.readByte() != 0; - this.mInReplyToStatusID = in.readString(); - this.mInReplyToUserID = in.readString(); - this.mInReplyToScreenName = in.readString(); - this.mThumbnailPic = in.readString(); - this.mBmiddlePic = in.readString(); - this.mOriginalPic = in.readString(); - this.mGeo = in.readParcelable(GeoModel.class.getClassLoader()); - this.mRetweetedStatus = in.readParcelable(MessageModel.class.getClassLoader()); - this.mRepostsCount = in.readInt(); - this.mCommentsCount = in.readInt(); - this.mAttitudesCount = in.readInt(); - this.mMLevel = in.readInt(); - this.mLongText = in.readParcelable(LongTextModel.class.getClassLoader()); - this.mVisible = in.readParcelable(WeiboVisibilityModel.class.getClassLoader()); - this.mPicUrls = new ArrayList(); - in.readList(this.mPicUrls, PictureModel.class.getClassLoader()); - int mUserTimelineImageSize = in.readInt(); - if (mUserTimelineImageSize != -1) { - this.mUserTimelineImage = new HashMap(mUserTimelineImageSize); - for (int i = 0; i < mUserTimelineImageSize; i++) { - String key = in.readString(); - UserTimelineImageModel value = in.readParcelable(UserTimelineImageModel.class.getClassLoader()); - this.mUserTimelineImage.put(key, value); - } - } - this.mID = in.readLong(); - this.mMID = in.readLong(); - this.mIDStr = in.readString(); - this.mCreatedAt = in.readString(); - this.mText = in.readString(); - this.mSource = in.readString(); - this.mUser = in.readParcelable(UserModel.class.getClassLoader()); - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public MessageModel createFromParcel(Parcel source) { - return new MessageModel(source); - } - - @Override - public MessageModel[] newArray(int size) { - return new MessageModel[size]; - } - }; -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/MessageModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/status/MessageModel.kt new file mode 100644 index 0000000..021fc8c --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/status/MessageModel.kt @@ -0,0 +1,162 @@ +package moe.tlaster.openween.core.model.status + +import android.os.Parcel +import android.os.Parcelable + +import com.google.gson.annotations.SerializedName + +import java.util.ArrayList +import java.util.HashMap + +import moe.tlaster.openween.core.model.BaseModel +import moe.tlaster.openween.core.model.GeoModel +import moe.tlaster.openween.core.model.user.UserModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class MessageModel : BaseModel, Parcelable { + @SerializedName("favorited") + var isFavorited: Boolean = false + @SerializedName("truncated") + var isTruncated: Boolean = false + @SerializedName("liked") + var isLiked: Boolean = false + @SerializedName("in_reply_to_status_id") + var inReplyToStatusID: String? = null + @SerializedName("in_reply_to_user_id") + var inReplyToUserID: String? = null + @SerializedName("in_reply_to_screen_name") + var inReplyToScreenName: String? = null + @SerializedName("thumbnail_pic") + var thumbnailPic: String? = null + @SerializedName("bmiddle_pic") + var bmiddlePic: String? = null + @SerializedName("original_pic") + var originalPic: String? = null + @SerializedName("geo") + var geo: GeoModel? = null + @SerializedName("retweeted_status") + var retweetedStatus: MessageModel? = null + @SerializedName("reposts_count") + var repostsCount: Int = 0 + @SerializedName("comments_count") + var commentsCount: Int = 0 + @SerializedName("attitudes_count") + var attitudesCount: Int = 0 + @SerializedName("mlevel") + var level: Int = 0 + @SerializedName("longText") + var longText: LongTextModel? = null + @SerializedName("visible") + var visible: WeiboVisibilityModel? = null + @SerializedName("pic_urls") + private var mPicUrls: List? = null + @SerializedName("pic_infos") + private var userTimelineImage: MutableMap? = null + + + var picUrls: List ? + get() = if (mPicUrls == null && userTimelineImage != null) + userTimelineImage!!.values.map(::PictureModel) + else + mPicUrls + set(picUrls) { + mPicUrls = picUrls + } + + override fun describeContents(): Int { + return 0 + } + + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeByte(if (this.isFavorited) 1.toByte() else 0.toByte()) + dest.writeByte(if (this.isTruncated) 1.toByte() else 0.toByte()) + dest.writeByte(if (this.isLiked) 1.toByte() else 0.toByte()) + dest.writeString(this.inReplyToStatusID) + dest.writeString(this.inReplyToUserID) + dest.writeString(this.inReplyToScreenName) + dest.writeString(this.thumbnailPic) + dest.writeString(this.bmiddlePic) + dest.writeString(this.originalPic) + dest.writeParcelable(this.geo, flags) + dest.writeParcelable(this.retweetedStatus, flags) + dest.writeInt(this.repostsCount) + dest.writeInt(this.commentsCount) + dest.writeInt(this.attitudesCount) + dest.writeInt(this.level) + dest.writeParcelable(this.longText, flags) + dest.writeParcelable(this.visible, flags) + dest.writeList(this.mPicUrls) + if (userTimelineImage != null) { + dest.writeInt(this.userTimelineImage!!.size) + for ((key, value) in this.userTimelineImage!!) { + dest.writeString(key) + dest.writeParcelable(value, flags) + } + } else { + dest.writeInt(-1) + } + dest.writeLong(this.id) + dest.writeLong(this.mid) + dest.writeString(this.idStr) + dest.writeString(this.createdAt) + dest.writeString(this.text) + dest.writeString(this.source) + dest.writeParcelable(this.user, flags) + } + + constructor() { + } + + protected constructor(`in`: Parcel) { + this.isFavorited = `in`.readByte().toInt() != 0 + this.isTruncated = `in`.readByte().toInt() != 0 + this.isLiked = `in`.readByte().toInt() != 0 + this.inReplyToStatusID = `in`.readString() + this.inReplyToUserID = `in`.readString() + this.inReplyToScreenName = `in`.readString() + this.thumbnailPic = `in`.readString() + this.bmiddlePic = `in`.readString() + this.originalPic = `in`.readString() + this.geo = `in`.readParcelable(GeoModel::class.java.classLoader) + this.retweetedStatus = `in`.readParcelable(MessageModel::class.java.classLoader) + this.repostsCount = `in`.readInt() + this.commentsCount = `in`.readInt() + this.attitudesCount = `in`.readInt() + this.level = `in`.readInt() + this.longText = `in`.readParcelable(LongTextModel::class.java.classLoader) + this.visible = `in`.readParcelable(WeiboVisibilityModel::class.java.classLoader) + this.mPicUrls = ArrayList() + `in`.readList(this.mPicUrls, PictureModel::class.java.classLoader) + val mUserTimelineImageSize = `in`.readInt() + if (mUserTimelineImageSize != -1) { + this.userTimelineImage = HashMap(mUserTimelineImageSize) + for (i in 0..mUserTimelineImageSize - 1) { + val key = `in`.readString() + val value = `in`.readParcelable(UserTimelineImageModel::class.java.classLoader) + this.userTimelineImage!!.put(key, value) + } + } + this.id = `in`.readLong() + this.mid = `in`.readLong() + this.idStr = `in`.readString() + this.createdAt = `in`.readString() + this.text = `in`.readString() + this.source = `in`.readString() + this.user = `in`.readParcelable(UserModel::class.java.classLoader) + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): MessageModel { + return MessageModel(source) + } + + override fun newArray(size: Int): Array { + return kotlin.arrayOfNulls(size) + } + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/PictureModel.java b/app/src/main/java/moe/tlaster/openween/core/model/status/PictureModel.java deleted file mode 100644 index b6f5fa8..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/status/PictureModel.java +++ /dev/null @@ -1,109 +0,0 @@ -package moe.tlaster.openween.core.model.status; - -import android.os.Parcel; -import android.os.Parcelable; -import android.text.TextUtils; - -import com.google.gson.annotations.SerializedName; - -import java.util.Map; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class PictureModel implements Parcelable { - @SerializedName("pic_id") - private String mPicID; - @SerializedName("thumbnail_pic") - private String mThumbnailPic; - @SerializedName("bmiddle_pic") - private String mBmiddlePic; - @SerializedName("original_pic") - private String mOriginalPic; - - public PictureModel() { - - } - - PictureModel(UserTimelineImageModel item) { - if (item != null){ - mPicID = item.getPicId(); - mThumbnailPic = item.getThumbnail().getUrl(); - mBmiddlePic = item.getBmiddle().getUrl(); - mOriginalPic = item.getOriginal().getUrl(); - } - } - - public String getPicID() { - return mPicID; - } - - public void setPicID(String picID) { - mPicID = picID; - } - - public String getThumbnailPic() { - return mThumbnailPic; - } - public String toLarge() { - if (TextUtils.isEmpty(mOriginalPic)) - return mThumbnailPic.replace("thumbnail", "large"); - else - return mOriginalPic; - } - public String toBmiddle() { - return mThumbnailPic.replace("thumbnail", "bmiddle"); - } - - public void setThumbnailPic(String thumbnailPic) { - mThumbnailPic = thumbnailPic; - } - - public String getBmiddlePic() { - return mBmiddlePic; - } - - public void setBmiddlePic(String bmiddlePic) { - mBmiddlePic = bmiddlePic; - } - - public String getOriginalPic() { - return mOriginalPic; - } - - public void setOriginalPic(String originalPic) { - mOriginalPic = originalPic; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(this.mPicID); - dest.writeString(this.mThumbnailPic); - dest.writeString(this.mBmiddlePic); - dest.writeString(this.mOriginalPic); - } - - protected PictureModel(Parcel in) { - this.mPicID = in.readString(); - this.mThumbnailPic = in.readString(); - this.mBmiddlePic = in.readString(); - this.mOriginalPic = in.readString(); - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public PictureModel createFromParcel(Parcel source) { - return new PictureModel(source); - } - - @Override - public PictureModel[] newArray(int size) { - return new PictureModel[size]; - } - }; -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/PictureModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/status/PictureModel.kt new file mode 100644 index 0000000..7515cec --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/status/PictureModel.kt @@ -0,0 +1,76 @@ +package moe.tlaster.openween.core.model.status + +import android.os.Parcel +import android.os.Parcelable +import android.text.TextUtils + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +class PictureModel : Parcelable { + @SerializedName("pic_id") + var picID: String? = null + @SerializedName("thumbnail_pic") + var thumbnailPic: String? = null + @SerializedName("bmiddle_pic") + var bmiddlePic: String? = null + @SerializedName("original_pic") + var originalPic: String? = null + + constructor() { + + } + + internal constructor(item: UserTimelineImageModel?) { + if (item != null) { + picID = item.picId + thumbnailPic = item.thumbnail?.url + bmiddlePic = item.bmiddle?.url + originalPic = item.original?.url + } + } + + fun toLarge(): String { + if (TextUtils.isEmpty(originalPic)) + return thumbnailPic!!.replace("thumbnail", "large") + else + return originalPic!! + } + + fun toBmiddle(): String { + return thumbnailPic!!.replace("thumbnail", "bmiddle") + } + + override fun describeContents(): Int { + return 0 + } + + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeString(this.picID) + dest.writeString(this.thumbnailPic) + dest.writeString(this.bmiddlePic) + dest.writeString(this.originalPic) + } + + protected constructor(`in`: Parcel) { + this.picID = `in`.readString() + this.thumbnailPic = `in`.readString() + this.bmiddlePic = `in`.readString() + this.originalPic = `in`.readString() + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): PictureModel { + return PictureModel(source) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/RepostListModel.java b/app/src/main/java/moe/tlaster/openween/core/model/status/RepostListModel.java deleted file mode 100644 index 0edef5d..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/status/RepostListModel.java +++ /dev/null @@ -1,24 +0,0 @@ -package moe.tlaster.openween.core.model.status; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -import moe.tlaster.openween.core.model.BaseListModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class RepostListModel extends BaseListModel { - - @SerializedName("reposts") - public List mReposts; - - public List getReposts() { - return mReposts; - } - - public void setReposts(List reposts) { - mReposts = reposts; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/RepostListModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/status/RepostListModel.kt new file mode 100644 index 0000000..62b23ad --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/status/RepostListModel.kt @@ -0,0 +1,14 @@ +package moe.tlaster.openween.core.model.status + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.BaseListModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class RepostListModel : BaseListModel() { + + @SerializedName("reposts") + var reposts: List? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/UserTimelineImageDetailModel.java b/app/src/main/java/moe/tlaster/openween/core/model/status/UserTimelineImageDetailModel.java deleted file mode 100644 index 6398e26..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/status/UserTimelineImageDetailModel.java +++ /dev/null @@ -1,76 +0,0 @@ -package moe.tlaster.openween.core.model.status; - -import android.os.Parcel; -import android.os.Parcelable; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Asahi on 2016/10/10. - */ - -public class UserTimelineImageDetailModel implements Parcelable { - @SerializedName("url") - private String mUrl; - @SerializedName("width") - private int mWidth; - @SerializedName("height") - private int mHeight; - - public String getUrl() { - return mUrl; - } - - public void setUrl(String url) { - mUrl = url; - } - - public int getWidth() { - return mWidth; - } - - public void setWidth(int width) { - mWidth = width; - } - - public int getHeight() { - return mHeight; - } - - public void setHeight(int height) { - mHeight = height; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(this.mUrl); - dest.writeInt(this.mWidth); - dest.writeInt(this.mHeight); - } - - public UserTimelineImageDetailModel() { - } - - protected UserTimelineImageDetailModel(Parcel in) { - this.mUrl = in.readString(); - this.mWidth = in.readInt(); - this.mHeight = in.readInt(); - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public UserTimelineImageDetailModel createFromParcel(Parcel source) { - return new UserTimelineImageDetailModel(source); - } - - @Override - public UserTimelineImageDetailModel[] newArray(int size) { - return new UserTimelineImageDetailModel[size]; - } - }; -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/UserTimelineImageDetailModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/status/UserTimelineImageDetailModel.kt new file mode 100644 index 0000000..6126209 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/status/UserTimelineImageDetailModel.kt @@ -0,0 +1,51 @@ +package moe.tlaster.openween.core.model.status + +import android.os.Parcel +import android.os.Parcelable + +import com.google.gson.annotations.SerializedName + +/** + * Created by Asahi on 2016/10/10. + */ + +class UserTimelineImageDetailModel : Parcelable { + @SerializedName("url") + var url: String? = null + @SerializedName("width") + var width: Int = 0 + @SerializedName("height") + var height: Int = 0 + + override fun describeContents(): Int { + return 0 + } + + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeString(this.url) + dest.writeInt(this.width) + dest.writeInt(this.height) + } + + constructor() { + } + + protected constructor(`in`: Parcel) { + this.url = `in`.readString() + this.width = `in`.readInt() + this.height = `in`.readInt() + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): UserTimelineImageDetailModel { + return UserTimelineImageDetailModel(source) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/UserTimelineImageModel.java b/app/src/main/java/moe/tlaster/openween/core/model/status/UserTimelineImageModel.java deleted file mode 100644 index 643a190..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/status/UserTimelineImageModel.java +++ /dev/null @@ -1,124 +0,0 @@ -package moe.tlaster.openween.core.model.status; - -import android.os.Parcel; -import android.os.Parcelable; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Asahi on 2016/10/10. - */ - -public class UserTimelineImageModel implements Parcelable { - @SerializedName("thumbnail") - private UserTimelineImageDetailModel mThumbnail; - @SerializedName("bmiddle") - private UserTimelineImageDetailModel mBmiddle; - @SerializedName("middleplus") - private UserTimelineImageDetailModel mMiddleplus; - @SerializedName("large") - private UserTimelineImageDetailModel mLarge; - @SerializedName("original") - private UserTimelineImageDetailModel mOriginal; - @SerializedName("largest") - private UserTimelineImageDetailModel mLargest; - @SerializedName("pic_id") - private String mPicId; - - public UserTimelineImageDetailModel getThumbnail() { - return mThumbnail; - } - - public void setThumbnail(UserTimelineImageDetailModel thumbnail) { - mThumbnail = thumbnail; - } - - public UserTimelineImageDetailModel getBmiddle() { - return mBmiddle; - } - - public void setBmiddle(UserTimelineImageDetailModel bmiddle) { - mBmiddle = bmiddle; - } - - public UserTimelineImageDetailModel getMiddleplus() { - return mMiddleplus; - } - - public void setMiddleplus(UserTimelineImageDetailModel middleplus) { - mMiddleplus = middleplus; - } - - public UserTimelineImageDetailModel getLarge() { - return mLarge; - } - - public void setLarge(UserTimelineImageDetailModel large) { - mLarge = large; - } - - public UserTimelineImageDetailModel getOriginal() { - return mOriginal; - } - - public void setOriginal(UserTimelineImageDetailModel original) { - mOriginal = original; - } - - public UserTimelineImageDetailModel getLargest() { - return mLargest; - } - - public void setLargest(UserTimelineImageDetailModel largest) { - mLargest = largest; - } - - public String getPicId() { - return mPicId; - } - - public void setPicId(String picId) { - mPicId = picId; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeParcelable(this.mThumbnail, flags); - dest.writeParcelable(this.mBmiddle, flags); - dest.writeParcelable(this.mMiddleplus, flags); - dest.writeParcelable(this.mLarge, flags); - dest.writeParcelable(this.mOriginal, flags); - dest.writeParcelable(this.mLargest, flags); - dest.writeString(this.mPicId); - } - - public UserTimelineImageModel() { - } - - protected UserTimelineImageModel(Parcel in) { - this.mThumbnail = in.readParcelable(UserTimelineImageDetailModel.class.getClassLoader()); - this.mBmiddle = in.readParcelable(UserTimelineImageDetailModel.class.getClassLoader()); - this.mMiddleplus = in.readParcelable(UserTimelineImageDetailModel.class.getClassLoader()); - this.mLarge = in.readParcelable(UserTimelineImageDetailModel.class.getClassLoader()); - this.mOriginal = in.readParcelable(UserTimelineImageDetailModel.class.getClassLoader()); - this.mLargest = in.readParcelable(UserTimelineImageDetailModel.class.getClassLoader()); - this.mPicId = in.readString(); - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public UserTimelineImageModel createFromParcel(Parcel source) { - return new UserTimelineImageModel(source); - } - - @Override - public UserTimelineImageModel[] newArray(int size) { - return new UserTimelineImageModel[size]; - } - }; -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/UserTimelineImageModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/status/UserTimelineImageModel.kt new file mode 100644 index 0000000..cae391b --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/status/UserTimelineImageModel.kt @@ -0,0 +1,67 @@ +package moe.tlaster.openween.core.model.status + +import android.os.Parcel +import android.os.Parcelable + +import com.google.gson.annotations.SerializedName + +/** + * Created by Asahi on 2016/10/10. + */ + +class UserTimelineImageModel : Parcelable { + @SerializedName("thumbnail") + var thumbnail: UserTimelineImageDetailModel? = null + @SerializedName("bmiddle") + var bmiddle: UserTimelineImageDetailModel? = null + @SerializedName("middleplus") + var middleplus: UserTimelineImageDetailModel? = null + @SerializedName("large") + var large: UserTimelineImageDetailModel? = null + @SerializedName("original") + var original: UserTimelineImageDetailModel? = null + @SerializedName("largest") + var largest: UserTimelineImageDetailModel? = null + @SerializedName("pic_id") + var picId: String? = null + + override fun describeContents(): Int { + return 0 + } + + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeParcelable(this.thumbnail, flags) + dest.writeParcelable(this.bmiddle, flags) + dest.writeParcelable(this.middleplus, flags) + dest.writeParcelable(this.large, flags) + dest.writeParcelable(this.original, flags) + dest.writeParcelable(this.largest, flags) + dest.writeString(this.picId) + } + + constructor() { + } + + protected constructor(`in`: Parcel) { + this.thumbnail = `in`.readParcelable(UserTimelineImageDetailModel::class.java.classLoader) + this.bmiddle = `in`.readParcelable(UserTimelineImageDetailModel::class.java.classLoader) + this.middleplus = `in`.readParcelable(UserTimelineImageDetailModel::class.java.classLoader) + this.large = `in`.readParcelable(UserTimelineImageDetailModel::class.java.classLoader) + this.original = `in`.readParcelable(UserTimelineImageDetailModel::class.java.classLoader) + this.largest = `in`.readParcelable(UserTimelineImageDetailModel::class.java.classLoader) + this.picId = `in`.readString() + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): UserTimelineImageModel { + return UserTimelineImageModel(source) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/WeiboVisibilityModel.java b/app/src/main/java/moe/tlaster/openween/core/model/status/WeiboVisibilityModel.java deleted file mode 100644 index ad9c341..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/status/WeiboVisibilityModel.java +++ /dev/null @@ -1,66 +0,0 @@ -package moe.tlaster.openween.core.model.status; - -import android.os.Parcel; -import android.os.Parcelable; - -import com.google.gson.annotations.SerializedName; - -import moe.tlaster.openween.core.model.types.WeiboVisibility; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class WeiboVisibilityModel implements Parcelable { - @SerializedName("type") - private WeiboVisibility mVisibility; - @SerializedName("list_id") - private int mListID; - - public WeiboVisibility getVisibility() { - return mVisibility; - } - - public void setVisibility(WeiboVisibility visibility) { - mVisibility = visibility; - } - - public int getListID() { - return mListID; - } - - public void setListID(int listID) { - mListID = listID; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(this.mVisibility == null ? -1 : this.mVisibility.ordinal()); - dest.writeInt(this.mListID); - } - - public WeiboVisibilityModel() { - } - - protected WeiboVisibilityModel(Parcel in) { - int tmpMVisibility = in.readInt(); - this.mVisibility = tmpMVisibility == -1 ? null : WeiboVisibility.values()[tmpMVisibility]; - this.mListID = in.readInt(); - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public WeiboVisibilityModel createFromParcel(Parcel source) { - return new WeiboVisibilityModel(source); - } - - @Override - public WeiboVisibilityModel[] newArray(int size) { - return new WeiboVisibilityModel[size]; - } - }; -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/status/WeiboVisibilityModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/status/WeiboVisibilityModel.kt new file mode 100644 index 0000000..8960344 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/status/WeiboVisibilityModel.kt @@ -0,0 +1,49 @@ +package moe.tlaster.openween.core.model.status + +import android.os.Parcel +import android.os.Parcelable + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.types.WeiboVisibility + +/** + * Created by Tlaster on 2016/9/2. + */ +class WeiboVisibilityModel : Parcelable { + @SerializedName("type") + var visibility: WeiboVisibility? = null + @SerializedName("list_id") + var listID: Int = 0 + + override fun describeContents(): Int { + return 0 + } + + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeInt(if (this.visibility == null) -1 else this.visibility!!.ordinal) + dest.writeInt(this.listID) + } + + constructor() { + } + + protected constructor(`in`: Parcel) { + val tmpMVisibility = `in`.readInt() + this.visibility = if (tmpMVisibility == -1) null else WeiboVisibility.values()[tmpMVisibility] + this.listID = `in`.readInt() + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): WeiboVisibilityModel { + return WeiboVisibilityModel(source) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/AuthorType.java b/app/src/main/java/moe/tlaster/openween/core/model/types/AuthorType.java deleted file mode 100644 index c62580a..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/types/AuthorType.java +++ /dev/null @@ -1,19 +0,0 @@ -package moe.tlaster.openween.core.model.types; - -/** - * Created by Tlaster on 2016/9/2. - */ -public enum AuthorType { - - All(0), - FollowedOnly(1), - Stranger(2); - - private final int value; - public int getValue() { - return value; - } - AuthorType(int value) { - this.value = value; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/AuthorType.kt b/app/src/main/java/moe/tlaster/openween/core/model/types/AuthorType.kt new file mode 100644 index 0000000..9851878 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/types/AuthorType.kt @@ -0,0 +1,11 @@ +package moe.tlaster.openween.core.model.types + +/** + * Created by Tlaster on 2016/9/2. + */ +enum class AuthorType constructor(val value: Int) { + + All(0), + FollowedOnly(1), + Stranger(2) +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/DirectMessageType.java b/app/src/main/java/moe/tlaster/openween/core/model/types/DirectMessageType.java deleted file mode 100644 index 032a7fd..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/types/DirectMessageType.java +++ /dev/null @@ -1,18 +0,0 @@ -package moe.tlaster.openween.core.model.types; - -/** - * Created by Tlaster on 2016/9/2. - */ -public enum DirectMessageType { - - Outbox(0), - Inbox(1),; - - private final int value; - public int getValue() { - return value; - } - DirectMessageType(int value) { - this.value = value; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/DirectMessageType.kt b/app/src/main/java/moe/tlaster/openween/core/model/types/DirectMessageType.kt new file mode 100644 index 0000000..e914948 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/types/DirectMessageType.kt @@ -0,0 +1,10 @@ +package moe.tlaster.openween.core.model.types + +/** + * Created by Tlaster on 2016/9/2. + */ +enum class DirectMessageType constructor(val value: Int) { + + Outbox(0), + Inbox(1) +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/FeatureType.java b/app/src/main/java/moe/tlaster/openween/core/model/types/FeatureType.java deleted file mode 100644 index f651711..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/types/FeatureType.java +++ /dev/null @@ -1,20 +0,0 @@ -package moe.tlaster.openween.core.model.types; - -/** - * Created by Tlaster on 2016/9/2. - */ -public enum FeatureType { - All(0), - Origin(1), - Picture(2), - Video(3), - Music(4); - - private final int value; - public int getValue() { - return value; - } - FeatureType(int value) { - this.value = value; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/FeatureType.kt b/app/src/main/java/moe/tlaster/openween/core/model/types/FeatureType.kt new file mode 100644 index 0000000..962a425 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/types/FeatureType.kt @@ -0,0 +1,12 @@ +package moe.tlaster.openween.core.model.types + +/** + * Created by Tlaster on 2016/9/2. + */ +enum class FeatureType constructor(val value: Int) { + All(0), + Origin(1), + Picture(2), + Video(3), + Music(4) +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/QueryType.java b/app/src/main/java/moe/tlaster/openween/core/model/types/QueryType.java deleted file mode 100644 index 962dc52..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/types/QueryType.java +++ /dev/null @@ -1,18 +0,0 @@ -package moe.tlaster.openween.core.model.types; - -/** - * Created by Tlaster on 2016/9/2. - */ -public enum QueryType { - Weibo(1), - Comment(2), - DirectMessage(3),; - - private final int value; - public int getValue() { - return value; - } - QueryType(int value) { - this.value = value; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/QueryType.kt b/app/src/main/java/moe/tlaster/openween/core/model/types/QueryType.kt new file mode 100644 index 0000000..f12f7d9 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/types/QueryType.kt @@ -0,0 +1,10 @@ +package moe.tlaster.openween.core.model.types + +/** + * Created by Tlaster on 2016/9/2. + */ +enum class QueryType constructor(val value: Int) { + Weibo(1), + Comment(2), + DirectMessage(3) +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/RemindType.java b/app/src/main/java/moe/tlaster/openween/core/model/types/RemindType.kt similarity index 57% rename from app/src/main/java/moe/tlaster/openween/core/model/types/RemindType.java rename to app/src/main/java/moe/tlaster/openween/core/model/types/RemindType.kt index b184b55..8d3a95d 100644 --- a/app/src/main/java/moe/tlaster/openween/core/model/types/RemindType.java +++ b/app/src/main/java/moe/tlaster/openween/core/model/types/RemindType.kt @@ -1,9 +1,9 @@ -package moe.tlaster.openween.core.model.types; +package moe.tlaster.openween.core.model.types /** * Created by Tlaster on 2016/9/7. */ -public enum RemindType { +enum class RemindType constructor(private val text: String) { Follower("follower"), Comment("cmt"), @@ -16,13 +16,8 @@ public enum RemindType { Badge("badge"), Photo("photo"); - private final String text; - RemindType(final String text) { - this.text = text; - } - - public String toString() { - return text; + override fun toString(): String { + return text } } diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/RepostType.java b/app/src/main/java/moe/tlaster/openween/core/model/types/RepostType.java deleted file mode 100644 index 5e2d2d6..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/types/RepostType.java +++ /dev/null @@ -1,19 +0,0 @@ -package moe.tlaster.openween.core.model.types; - -/** - * Created by Tlaster on 2016/9/2. - */ -public enum RepostType { - None(0), - CommentCurrentWeibo(1), - CommentOriginWeibo(2), - CommentAll(3),; - - private final int value; - public int getValue() { - return value; - } - RepostType(int value) { - this.value = value; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/RepostType.kt b/app/src/main/java/moe/tlaster/openween/core/model/types/RepostType.kt new file mode 100644 index 0000000..1d04016 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/types/RepostType.kt @@ -0,0 +1,11 @@ +package moe.tlaster.openween.core.model.types + +/** + * Created by Tlaster on 2016/9/2. + */ +enum class RepostType constructor(val value: Int) { + None(0), + CommentCurrentWeibo(1), + CommentOriginWeibo(2), + CommentAll(3) +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/ShieldType.java b/app/src/main/java/moe/tlaster/openween/core/model/types/ShieldType.java deleted file mode 100644 index 941e96a..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/types/ShieldType.java +++ /dev/null @@ -1,17 +0,0 @@ -package moe.tlaster.openween.core.model.types; - -/** - * Created by Tlaster on 2016/9/2. - */ -public enum ShieldType { - CurrentOnly(0), - WithFollowUp(1),; - - private final int value; - public int getValue() { - return value; - } - ShieldType(int value) { - this.value = value; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/ShieldType.kt b/app/src/main/java/moe/tlaster/openween/core/model/types/ShieldType.kt new file mode 100644 index 0000000..4d7ed5d --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/types/ShieldType.kt @@ -0,0 +1,9 @@ +package moe.tlaster.openween.core.model.types + +/** + * Created by Tlaster on 2016/9/2. + */ +enum class ShieldType constructor(val value: Int) { + CurrentOnly(0), + WithFollowUp(1) +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/SourceType.java b/app/src/main/java/moe/tlaster/openween/core/model/types/SourceType.java deleted file mode 100644 index 63cd451..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/types/SourceType.java +++ /dev/null @@ -1,18 +0,0 @@ -package moe.tlaster.openween.core.model.types; - -/** - * Created by Tlaster on 2016/9/2. - */ -public enum SourceType { - All(0), - Weibo(1), - MicroGroup(2); - - private final int value; - public int getValue() { - return value; - } - SourceType(int value) { - this.value = value; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/SourceType.kt b/app/src/main/java/moe/tlaster/openween/core/model/types/SourceType.kt new file mode 100644 index 0000000..2915837 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/types/SourceType.kt @@ -0,0 +1,10 @@ +package moe.tlaster.openween.core.model.types + +/** + * Created by Tlaster on 2016/9/2. + */ +enum class SourceType constructor(val value: Int) { + All(0), + Weibo(1), + MicroGroup(2) +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/UrlType.java b/app/src/main/java/moe/tlaster/openween/core/model/types/UrlType.java deleted file mode 100644 index c97f1cf..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/types/UrlType.java +++ /dev/null @@ -1,21 +0,0 @@ -package moe.tlaster.openween.core.model.types; - -/** - * Created by Tlaster on 2016/9/2. - */ -public enum UrlType { - WebLink(0), - Video(1), - Music(2), - Event(3), - Vote(5); - - UrlType(int i) { - this.value = i; - } - - private final int value; - public int getValue() { - return value; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/UrlType.kt b/app/src/main/java/moe/tlaster/openween/core/model/types/UrlType.kt new file mode 100644 index 0000000..77f8027 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/types/UrlType.kt @@ -0,0 +1,12 @@ +package moe.tlaster.openween.core.model.types + +/** + * Created by Tlaster on 2016/9/2. + */ +enum class UrlType private constructor(val value: Int) { + WebLink(0), + Video(1), + Music(2), + Event(3), + Vote(5) +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/WeiboVisibility.java b/app/src/main/java/moe/tlaster/openween/core/model/types/WeiboVisibility.java deleted file mode 100644 index f99cb82..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/types/WeiboVisibility.java +++ /dev/null @@ -1,19 +0,0 @@ -package moe.tlaster.openween.core.model.types; - -/** - * Created by Tlaster on 2016/9/2. - */ -public enum WeiboVisibility { - All(0), - OnlyMe(1), - OnlyFriends(2), - SpecifiedGroup(3); - - private final int value; - public int getValue() { - return value; - } - WeiboVisibility(int value) { - this.value = value; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/types/WeiboVisibility.kt b/app/src/main/java/moe/tlaster/openween/core/model/types/WeiboVisibility.kt new file mode 100644 index 0000000..1ab4686 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/types/WeiboVisibility.kt @@ -0,0 +1,11 @@ +package moe.tlaster.openween.core.model.types + +/** + * Created by Tlaster on 2016/9/2. + */ +enum class WeiboVisibility constructor(val value: Int) { + All(0), + OnlyMe(1), + OnlyFriends(2), + SpecifiedGroup(3) +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/url/AnnotationModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/url/AnnotationModel.kt new file mode 100644 index 0000000..3c8257d --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/url/AnnotationModel.kt @@ -0,0 +1,11 @@ +package moe.tlaster.openween.core.model.url + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +class AnnotationModel { + @SerializedName("object") + var item: ObjectModel? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/url/ObjectModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/url/ObjectModel.kt new file mode 100644 index 0000000..1048075 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/url/ObjectModel.kt @@ -0,0 +1,23 @@ +package moe.tlaster.openween.core.model.url + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +class ObjectModel { + @SerializedName("url") + var url: String? = null + @SerializedName("display_name") + var displayName: String? = null + @SerializedName("pic_ids") + var picIds: Array? = null + @SerializedName("object_type") + var objectType: String? = null + @SerializedName("object") + var urlObject: Any? = null + @SerializedName("original_url") + var originalUrl: String? = null + @SerializedName("stream") + var stream: StreamModel? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/url/StreamModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/url/StreamModel.kt new file mode 100644 index 0000000..4f7b9be --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/url/StreamModel.kt @@ -0,0 +1,11 @@ +package moe.tlaster.openween.core.model.url + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +class StreamModel { + @SerializedName("url") + var url: String? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/url/UrlInfoListModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/url/UrlInfoListModel.kt new file mode 100644 index 0000000..b9b4b31 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/url/UrlInfoListModel.kt @@ -0,0 +1,13 @@ +package moe.tlaster.openween.core.model.url + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +class UrlInfoListModel { + + @SerializedName("urls") + var urls: List? = null + +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/url/UrlInfoModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/url/UrlInfoModel.kt new file mode 100644 index 0000000..c36a8f1 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/url/UrlInfoModel.kt @@ -0,0 +1,26 @@ +package moe.tlaster.openween.core.model.url + + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +class UrlInfoModel { + @SerializedName("result") + var isResult: Boolean = false + @SerializedName("last_modified") + var lastModified: Long = 0 + @SerializedName("title") + var title: String? = null + @SerializedName("description") + var description: String? = null + @SerializedName("url_short") + var urlShort: String? = null + @SerializedName("url_long") + var urlLong: String? = null + @SerializedName("annotations") + var annotations: List? = null + @SerializedName("type") + var type: Int = 0 +} \ No newline at end of file diff --git a/app/src/main/java/moe/tlaster/openween/core/model/user/UserBaseModel.java b/app/src/main/java/moe/tlaster/openween/core/model/user/UserBaseModel.java deleted file mode 100644 index bd6738e..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/user/UserBaseModel.java +++ /dev/null @@ -1,59 +0,0 @@ -package moe.tlaster.openween.core.model.user; - -import com.google.gson.annotations.SerializedName; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class UserBaseModel { - @SerializedName("id") - public long mID; - @SerializedName("idstr") - public String mIDStr; - @SerializedName("followers_count") - public int mFollowersCount = 0; - @SerializedName("friends_count") - public int mFriendsCount = 0; - @SerializedName("statuses_count") - public int mStatusesCount = 0; - - public long getID() { - return mID; - } - - public void setID(long ID) { - mID = ID; - } - - public String getIDStr() { - return mIDStr; - } - - public void setIDStr(String IDStr) { - mIDStr = IDStr; - } - - public int getFollowersCount() { - return mFollowersCount; - } - - public void setFollowersCount(int followersCount) { - mFollowersCount = followersCount; - } - - public int getFriendsCount() { - return mFriendsCount; - } - - public void setFriendsCount(int friendsCount) { - mFriendsCount = friendsCount; - } - - public int getStatusesCount() { - return mStatusesCount; - } - - public void setStatusesCount(int statusesCount) { - mStatusesCount = statusesCount; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/user/UserBaseModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/user/UserBaseModel.kt new file mode 100644 index 0000000..8d83f31 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/user/UserBaseModel.kt @@ -0,0 +1,19 @@ +package moe.tlaster.openween.core.model.user + +import com.google.gson.annotations.SerializedName + +/** + * Created by Tlaster on 2016/9/2. + */ +open class UserBaseModel { + @SerializedName("id") + var id: Long = 0 + @SerializedName("idstr") + var idStr: String? = null + @SerializedName("followers_count") + var followersCount = 0 + @SerializedName("friends_count") + var friendsCount = 0 + @SerializedName("statuses_count") + var statusesCount = 0 +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/user/UserListModel.java b/app/src/main/java/moe/tlaster/openween/core/model/user/UserListModel.java deleted file mode 100644 index d699e8f..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/user/UserListModel.java +++ /dev/null @@ -1,23 +0,0 @@ -package moe.tlaster.openween.core.model.user; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -import moe.tlaster.openween.core.model.BaseListModel; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class UserListModel extends BaseListModel { - @SerializedName("users") - private List mUsers; - - public List getUsers() { - return mUsers; - } - - public void setUsers(List users) { - mUsers = users; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/user/UserListModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/user/UserListModel.kt new file mode 100644 index 0000000..f211dec --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/user/UserListModel.kt @@ -0,0 +1,13 @@ +package moe.tlaster.openween.core.model.user + +import com.google.gson.annotations.SerializedName + +import moe.tlaster.openween.core.model.BaseListModel + +/** + * Created by Tlaster on 2016/9/2. + */ +class UserListModel : BaseListModel() { + @SerializedName("users") + var users: List? = null +} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/user/UserModel.java b/app/src/main/java/moe/tlaster/openween/core/model/user/UserModel.java deleted file mode 100644 index b44adab..0000000 --- a/app/src/main/java/moe/tlaster/openween/core/model/user/UserModel.java +++ /dev/null @@ -1,436 +0,0 @@ -package moe.tlaster.openween.core.model.user; - -import android.os.Parcel; -import android.os.Parcelable; - -import com.google.gson.annotations.SerializedName; - -import org.ocpsoft.prettytime.PrettyTime; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - -import moe.tlaster.openween.common.helpers.TimeHelper; - -/** - * Created by Tlaster on 2016/9/2. - */ -public class UserModel extends UserBaseModel implements Parcelable { - @SerializedName("screen_name") - private String mScreenName; - @SerializedName("name") - private String mName; - @SerializedName("remark") - private String mRemark; - @SerializedName("province") - private String mProvince; - @SerializedName("city") - private String mCity; - @SerializedName("location") - private String mLocation; - @SerializedName("description") - private String mDescription; - @SerializedName("url") - private String mUrl; - @SerializedName("profile_image_url") - private String mProfileImageUrl; - @SerializedName("domain") - private String mDomain; - @SerializedName("gender") - private String mGender; - @SerializedName("favourites_count") - private int mFavouritesCount = 0; - @SerializedName("verified_type") - private int mVerifiedType; - @SerializedName("created_at") - private String mCreatedAt; - @SerializedName("following") - private boolean mFollowing = false; - @SerializedName("allow_all_act_msg") - private boolean mAllowAllActMsg = false; - @SerializedName("geo_enabled") - private boolean mGeoEnabled = false; - @SerializedName("verified") - private boolean mVerified = false; - @SerializedName("allow_all_comment") - private boolean mAllowAllComment = false; - @SerializedName("avatar_large") - private String mAvatarLarge; - @SerializedName("verified_reason") - private String mVerifiedReason; - @SerializedName("follow_me") - private boolean mFollowMe = false; - @SerializedName("online_status") - private int mOnlineStatus = 0; - @SerializedName("bi_followers_count") - private int mBiFollowersCount = 0; - @SerializedName("cover_image") - private String mCoverimage = ""; - @SerializedName("cover_image_phone") - private String mCoverImagePhone; - @SerializedName("avatar_hd") - private String mAvatarHD; - @SerializedName("weihao") - private String mWeihao; - @SerializedName("lang") - private String mLang; - @SerializedName("level") - private int mLevel; - - - public String getCreatedAtDiffForHuman(){ - try { - return TimeHelper.getmPrettyTime().format(TimeHelper.getmSimpleDateFormat().parse(mCreatedAt)); - } catch (ParseException e) { - e.printStackTrace(); - } - return mCreatedAt; - } - - public Date getCreatedDate(){ - try { - return TimeHelper.getmSimpleDateFormat().parse(mCreatedAt); - } catch (ParseException e) { - return null; - } - } - - public String getScreenName() { - return mScreenName; - } - - public void setScreenName(String screenName) { - mScreenName = screenName; - } - - public String getName() { - return mName; - } - - public void setName(String name) { - mName = name; - } - - public String getRemark() { - return mRemark; - } - - public void setRemark(String remark) { - mRemark = remark; - } - - public String getProvince() { - return mProvince; - } - - public void setProvince(String province) { - mProvince = province; - } - - public String getCity() { - return mCity; - } - - public void setCity(String city) { - mCity = city; - } - - public String getLocation() { - return mLocation; - } - - public void setLocation(String location) { - mLocation = location; - } - - public String getDescription() { - return mDescription; - } - - public void setDescription(String description) { - mDescription = description; - } - - public String getUrl() { - return mUrl; - } - - public void setUrl(String url) { - mUrl = url; - } - - public String getProfileImageUrl() { - return mProfileImageUrl; - } - - public void setProfileImageUrl(String profileImageUrl) { - mProfileImageUrl = profileImageUrl; - } - - public String getDomain() { - return mDomain; - } - - public void setDomain(String domain) { - mDomain = domain; - } - - public String getGender() { - return mGender; - } - - public void setGender(String gender) { - mGender = gender; - } - - public int getFavouritesCount() { - return mFavouritesCount; - } - - public void setFavouritesCount(int favouritesCount) { - mFavouritesCount = favouritesCount; - } - - public int getVerifiedType() { - return mVerifiedType; - } - - public void setVerifiedType(int verifiedType) { - mVerifiedType = verifiedType; - } - - public String getCreatedAt() { - return mCreatedAt; - } - - public void setCreatedAt(String createdAt) { - mCreatedAt = createdAt; - } - - public boolean isFollowing() { - return mFollowing; - } - - public void setFollowing(boolean following) { - mFollowing = following; - } - - public boolean isAllowAllActMsg() { - return mAllowAllActMsg; - } - - public void setAllowAllActMsg(boolean allowAllActMsg) { - mAllowAllActMsg = allowAllActMsg; - } - - public boolean isGeoEnabled() { - return mGeoEnabled; - } - - public void setGeoEnabled(boolean geoEnabled) { - mGeoEnabled = geoEnabled; - } - - public boolean isVerified() { - return mVerified; - } - - public void setVerified(boolean verified) { - mVerified = verified; - } - - public boolean isAllowAllComment() { - return mAllowAllComment; - } - - public void setAllowAllComment(boolean allowAllComment) { - mAllowAllComment = allowAllComment; - } - - public String getAvatarLarge() { - return mAvatarLarge; - } - - public void setAvatarLarge(String avatarLarge) { - mAvatarLarge = avatarLarge; - } - - public String getVerifiedReason() { - return mVerifiedReason; - } - - public void setVerifiedReason(String verifiedReason) { - mVerifiedReason = verifiedReason; - } - - public boolean isFollowMe() { - return mFollowMe; - } - - public void setFollowMe(boolean followMe) { - mFollowMe = followMe; - } - - public int getOnlineStatus() { - return mOnlineStatus; - } - - public void setOnlineStatus(int onlineStatus) { - mOnlineStatus = onlineStatus; - } - - public int getBiFollowersCount() { - return mBiFollowersCount; - } - - public void setBiFollowersCount(int biFollowersCount) { - mBiFollowersCount = biFollowersCount; - } - - public String getCoverimage() { - return mCoverimage; - } - - public void setCoverimage(String coverimage) { - mCoverimage = coverimage; - } - - public String getCoverImagePhone() { - return mCoverImagePhone; - } - - public void setCoverImagePhone(String coverImagePhone) { - mCoverImagePhone = coverImagePhone; - } - - public String getAvatarHD() { - return mAvatarHD; - } - - public void setAvatarHD(String avatarHD) { - mAvatarHD = avatarHD; - } - - public String getWeihao() { - return mWeihao; - } - - public void setWeihao(String weihao) { - mWeihao = weihao; - } - - public String getLang() { - return mLang; - } - - public void setLang(String lang) { - mLang = lang; - } - - public int getLevel() { - return mLevel; - } - - public void setLevel(int level) { - mLevel = level; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(this.mScreenName); - dest.writeString(this.mName); - dest.writeString(this.mRemark); - dest.writeString(this.mProvince); - dest.writeString(this.mCity); - dest.writeString(this.mLocation); - dest.writeString(this.mDescription); - dest.writeString(this.mUrl); - dest.writeString(this.mProfileImageUrl); - dest.writeString(this.mDomain); - dest.writeString(this.mGender); - dest.writeInt(this.mFavouritesCount); - dest.writeInt(this.mVerifiedType); - dest.writeString(this.mCreatedAt); - dest.writeByte(this.mFollowing ? (byte) 1 : (byte) 0); - dest.writeByte(this.mAllowAllActMsg ? (byte) 1 : (byte) 0); - dest.writeByte(this.mGeoEnabled ? (byte) 1 : (byte) 0); - dest.writeByte(this.mVerified ? (byte) 1 : (byte) 0); - dest.writeByte(this.mAllowAllComment ? (byte) 1 : (byte) 0); - dest.writeString(this.mAvatarLarge); - dest.writeString(this.mVerifiedReason); - dest.writeByte(this.mFollowMe ? (byte) 1 : (byte) 0); - dest.writeInt(this.mOnlineStatus); - dest.writeInt(this.mBiFollowersCount); - dest.writeString(this.mCoverimage); - dest.writeString(this.mCoverImagePhone); - dest.writeString(this.mAvatarHD); - dest.writeString(this.mWeihao); - dest.writeString(this.mLang); - dest.writeInt(this.mLevel); - dest.writeLong(this.mID); - dest.writeString(this.mIDStr); - dest.writeInt(this.mFollowersCount); - dest.writeInt(this.mFriendsCount); - dest.writeInt(this.mStatusesCount); - } - - public UserModel() { - } - - protected UserModel(Parcel in) { - this.mScreenName = in.readString(); - this.mName = in.readString(); - this.mRemark = in.readString(); - this.mProvince = in.readString(); - this.mCity = in.readString(); - this.mLocation = in.readString(); - this.mDescription = in.readString(); - this.mUrl = in.readString(); - this.mProfileImageUrl = in.readString(); - this.mDomain = in.readString(); - this.mGender = in.readString(); - this.mFavouritesCount = in.readInt(); - this.mVerifiedType = in.readInt(); - this.mCreatedAt = in.readString(); - this.mFollowing = in.readByte() != 0; - this.mAllowAllActMsg = in.readByte() != 0; - this.mGeoEnabled = in.readByte() != 0; - this.mVerified = in.readByte() != 0; - this.mAllowAllComment = in.readByte() != 0; - this.mAvatarLarge = in.readString(); - this.mVerifiedReason = in.readString(); - this.mFollowMe = in.readByte() != 0; - this.mOnlineStatus = in.readInt(); - this.mBiFollowersCount = in.readInt(); - this.mCoverimage = in.readString(); - this.mCoverImagePhone = in.readString(); - this.mAvatarHD = in.readString(); - this.mWeihao = in.readString(); - this.mLang = in.readString(); - this.mLevel = in.readInt(); - this.mID = in.readLong(); - this.mIDStr = in.readString(); - this.mFollowersCount = in.readInt(); - this.mFriendsCount = in.readInt(); - this.mStatusesCount = in.readInt(); - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public UserModel createFromParcel(Parcel source) { - return new UserModel(source); - } - - @Override - public UserModel[] newArray(int size) { - return new UserModel[size]; - } - }; -} diff --git a/app/src/main/java/moe/tlaster/openween/core/model/user/UserModel.kt b/app/src/main/java/moe/tlaster/openween/core/model/user/UserModel.kt new file mode 100644 index 0000000..145f901 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/core/model/user/UserModel.kt @@ -0,0 +1,199 @@ +package moe.tlaster.openween.core.model.user + +import android.os.Parcel +import android.os.Parcelable + +import com.google.gson.annotations.SerializedName + +import org.ocpsoft.prettytime.PrettyTime + +import java.text.ParseException +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale + +import moe.tlaster.openween.common.helpers.TimeHelper + +/** + * Created by Tlaster on 2016/9/2. + */ +class UserModel : UserBaseModel, Parcelable { + @SerializedName("screen_name") + var screenName: String? = null + @SerializedName("name") + var name: String? = null + @SerializedName("remark") + var remark: String? = null + @SerializedName("province") + var province: String? = null + @SerializedName("city") + var city: String? = null + @SerializedName("location") + var location: String? = null + @SerializedName("description") + var description: String? = null + @SerializedName("url") + var url: String? = null + @SerializedName("profile_image_url") + var profileImageUrl: String? = null + @SerializedName("domain") + var domain: String? = null + @SerializedName("gender") + var gender: String? = null + @SerializedName("favourites_count") + var favouritesCount = 0 + @SerializedName("verified_type") + var verifiedType: Int = 0 + @SerializedName("created_at") + var createdAt: String? = null + @SerializedName("following") + var isFollowing = false + @SerializedName("allow_all_act_msg") + var isAllowAllActMsg = false + @SerializedName("geo_enabled") + var isGeoEnabled = false + @SerializedName("verified") + var isVerified = false + @SerializedName("allow_all_comment") + var isAllowAllComment = false + @SerializedName("avatar_large") + var avatarLarge: String? = null + @SerializedName("verified_reason") + var verifiedReason: String? = null + @SerializedName("follow_me") + var isFollowMe = false + @SerializedName("online_status") + var onlineStatus = 0 + @SerializedName("bi_followers_count") + var biFollowersCount = 0 + @SerializedName("cover_image") + var coverimage = "" + @SerializedName("cover_image_phone") + var coverImagePhone: String? = null + @SerializedName("avatar_hd") + var avatarHD: String? = null + @SerializedName("weihao") + var weihao: String? = null + @SerializedName("lang") + var lang: String? = null + @SerializedName("level") + var level: Int = 0 + + + val createdAtDiffForHuman: String + get() { + try { + return TimeHelper.prettyTime.format(TimeHelper.simpleDateFormat.parse(createdAt)) + } catch (e: ParseException) { + e.printStackTrace() + } + + return createdAt!! + } + + val createdDate: Date? + get() { + try { + return TimeHelper.simpleDateFormat.parse(createdAt) + } catch (e: ParseException) { + return null + } + + } + + override fun describeContents(): Int { + return 0 + } + + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeString(this.screenName) + dest.writeString(this.name) + dest.writeString(this.remark) + dest.writeString(this.province) + dest.writeString(this.city) + dest.writeString(this.location) + dest.writeString(this.description) + dest.writeString(this.url) + dest.writeString(this.profileImageUrl) + dest.writeString(this.domain) + dest.writeString(this.gender) + dest.writeInt(this.favouritesCount) + dest.writeInt(this.verifiedType) + dest.writeString(this.createdAt) + dest.writeByte(if (this.isFollowing) 1.toByte() else 0.toByte()) + dest.writeByte(if (this.isAllowAllActMsg) 1.toByte() else 0.toByte()) + dest.writeByte(if (this.isGeoEnabled) 1.toByte() else 0.toByte()) + dest.writeByte(if (this.isVerified) 1.toByte() else 0.toByte()) + dest.writeByte(if (this.isAllowAllComment) 1.toByte() else 0.toByte()) + dest.writeString(this.avatarLarge) + dest.writeString(this.verifiedReason) + dest.writeByte(if (this.isFollowMe) 1.toByte() else 0.toByte()) + dest.writeInt(this.onlineStatus) + dest.writeInt(this.biFollowersCount) + dest.writeString(this.coverimage) + dest.writeString(this.coverImagePhone) + dest.writeString(this.avatarHD) + dest.writeString(this.weihao) + dest.writeString(this.lang) + dest.writeInt(this.level) + dest.writeLong(this.id) + dest.writeString(this.idStr) + dest.writeInt(this.followersCount) + dest.writeInt(this.friendsCount) + dest.writeInt(this.statusesCount) + } + + constructor() { + } + + protected constructor(`in`: Parcel) { + this.screenName = `in`.readString() + this.name = `in`.readString() + this.remark = `in`.readString() + this.province = `in`.readString() + this.city = `in`.readString() + this.location = `in`.readString() + this.description = `in`.readString() + this.url = `in`.readString() + this.profileImageUrl = `in`.readString() + this.domain = `in`.readString() + this.gender = `in`.readString() + this.favouritesCount = `in`.readInt() + this.verifiedType = `in`.readInt() + this.createdAt = `in`.readString() + this.isFollowing = `in`.readByte().toInt() != 0 + this.isAllowAllActMsg = `in`.readByte().toInt() != 0 + this.isGeoEnabled = `in`.readByte().toInt() != 0 + this.isVerified = `in`.readByte().toInt() != 0 + this.isAllowAllComment = `in`.readByte().toInt() != 0 + this.avatarLarge = `in`.readString() + this.verifiedReason = `in`.readString() + this.isFollowMe = `in`.readByte().toInt() != 0 + this.onlineStatus = `in`.readInt() + this.biFollowersCount = `in`.readInt() + this.coverimage = `in`.readString() + this.coverImagePhone = `in`.readString() + this.avatarHD = `in`.readString() + this.weihao = `in`.readString() + this.lang = `in`.readString() + this.level = `in`.readInt() + this.id = `in`.readLong() + this.idStr = `in`.readString() + this.followersCount = `in`.readInt() + this.friendsCount = `in`.readInt() + this.statusesCount = `in`.readInt() + } + + companion object { + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): UserModel { + return UserModel(source) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/WeiboListBase.java b/app/src/main/java/moe/tlaster/openween/fragment/WeiboListBase.java deleted file mode 100644 index c261718..0000000 --- a/app/src/main/java/moe/tlaster/openween/fragment/WeiboListBase.java +++ /dev/null @@ -1,128 +0,0 @@ -package moe.tlaster.openween.fragment; - -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.text.TextUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Toast; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; - -import java.util.List; - -import moe.tlaster.openween.R; -import moe.tlaster.openween.adapter.BaseModelAdapter; -import moe.tlaster.openween.common.SimpleDividerItemDecoration; -import moe.tlaster.openween.common.StaticResource; -import moe.tlaster.openween.common.controls.Pivot; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.api.Entity; -import okhttp3.Call; - -/** - * Created by Tlaster on 2016/9/10. - */ -public abstract class WeiboListBase extends Pivot.PivotItemFragment { - protected interface Callback { - void onError(Exception e); - void onResponse(T response, int totalCount); - } - - protected RecyclerView mRecyclerView; - protected SwipeRefreshLayout mSwipeRefreshLayout; - protected BaseQuickAdapter mAdapter; - private int mTotalCount = 0; - protected int mLoadCount = 20; - protected int mPage = 1; - protected int getContentView() { - return R.layout.list_layout; - } - protected int getRecyclerView() { - return R.id.recyclerView; - } - protected int getSwipeRefreshLayout() { - return R.id.refresher; - } - protected RecyclerView.LayoutManager getLayoutManager(){ - return new LinearLayoutManager(getContext()); - } - protected BaseQuickAdapter initAdapter() { - return new BaseModelAdapter(); - } - - private boolean HasMore(){ - return mAdapter.getData().size() < mTotalCount; - } - - public void toTop() { - mRecyclerView.scrollToPosition(0); - } - - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(getContentView(), container, false); - mRecyclerView = (RecyclerView) view.findViewById(getRecyclerView()); - mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(getSwipeRefreshLayout()); - mSwipeRefreshLayout.setOnRefreshListener(this::refresh); - mRecyclerView.setLayoutManager(getLayoutManager()); - mAdapter = initAdapter(); - mAdapter.openLoadAnimation(); - mAdapter.openLoadMore(20); - mRecyclerView.setAdapter(mAdapter); - mAdapter.setOnLoadMoreListener(() -> mRecyclerView.post(this::loadMore)); - mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getContext())); - refresh(); - return view; - } - - private void loadMore() { - if (!HasMore() || TextUtils.isEmpty(Entity.getAccessToken())) { - mAdapter.loadComplete(); - mAdapter.addFooterView(getLayoutInflater(null).inflate(R.layout.not_loading, (ViewGroup) mRecyclerView.getParent(), false)); - return; - } - loadMoreOverride(new Callback>() { - @Override - public void onError(Exception e) { - //mAdapter.showLoadMoreFailedView();//TODO:Show refresh failed - Toast.makeText(getContext(), "加载失败", Toast.LENGTH_SHORT).show(); - } - - @Override - public void onResponse(List response, int totalCount) { - mAdapter.addData(response); - mTotalCount = totalCount; - } - }); - } - - public void refresh() { - if (TextUtils.isEmpty(Entity.getAccessToken())) return; - mSwipeRefreshLayout.post(()-> mSwipeRefreshLayout.setRefreshing(true)); - mPage = 1; - refreshOverride(new Callback>() { - @Override - public void onError(Exception e) { - //mAdapter.showLoadMoreFailedView();//TODO:Show refresh failed - Toast.makeText(getContext(), "加载失败", Toast.LENGTH_SHORT).show(); - mSwipeRefreshLayout.setRefreshing(false); - } - - @Override - public void onResponse(List response, int totalCount) { - mAdapter.setNewData(response); - mTotalCount = totalCount; - mSwipeRefreshLayout.setRefreshing(false); - } - }); - } - protected abstract void loadMoreOverride(Callback> callback); - protected abstract void refreshOverride(Callback> callback); -} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/WeiboListBase.kt b/app/src/main/java/moe/tlaster/openween/fragment/WeiboListBase.kt new file mode 100644 index 0000000..b30b852 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/fragment/WeiboListBase.kt @@ -0,0 +1,116 @@ +package moe.tlaster.openween.fragment + +import android.os.Bundle +import android.support.v4.widget.SwipeRefreshLayout +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.text.TextUtils +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast + +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder + +import moe.tlaster.openween.R +import moe.tlaster.openween.adapter.BaseModelAdapter +import moe.tlaster.openween.common.SimpleDividerItemDecoration +import moe.tlaster.openween.common.StaticResource +import moe.tlaster.openween.common.controls.Pivot +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.api.Entity +import moe.tlaster.openween.core.model.BaseModel +import okhttp3.Call + +/** + * Created by Tlaster on 2016/9/10. + */ +abstract class WeiboListBase : Pivot.PivotItemFragment() { + protected interface Callback { + fun onError(e: Exception) + fun onResponse(response: T, totalCount: Int) + } + + protected var mRecyclerView: RecyclerView? = null + protected var mSwipeRefreshLayout: SwipeRefreshLayout? = null + protected var mAdapter: BaseQuickAdapter? = null + private var mTotalCount = 0 + protected var mLoadCount = 20 + protected var mPage = 1 + protected val contentView: Int + get() = R.layout.list_layout + protected val recyclerView: Int + get() = R.id.recyclerView + protected val swipeRefreshLayout: Int + get() = R.id.refresher + protected val layoutManager: RecyclerView.LayoutManager + get() = LinearLayoutManager(context) + + protected abstract fun initAdapter(): BaseQuickAdapter + + private fun HasMore(): Boolean { + return mAdapter?.data?.size!! < mTotalCount + } + + fun toTop() { + mRecyclerView?.scrollToPosition(0) + } + + override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { + val view = inflater!!.inflate(contentView, container, false) + mRecyclerView = view.findViewById(recyclerView) as RecyclerView + mSwipeRefreshLayout = view.findViewById(swipeRefreshLayout) as SwipeRefreshLayout + mSwipeRefreshLayout?.setOnRefreshListener{ this.refresh() } + mRecyclerView?.layoutManager = layoutManager + mAdapter = initAdapter() + mAdapter?.openLoadAnimation() + mAdapter?.openLoadMore(20) + mRecyclerView?.adapter = mAdapter + mAdapter?.setOnLoadMoreListener { mRecyclerView?.post { this.loadMore() } } + mRecyclerView?.addItemDecoration(SimpleDividerItemDecoration(context)) + refresh() + return view + } + + private fun loadMore() { + if (!HasMore() || TextUtils.isEmpty(Entity.accessToken)) { + mAdapter?.loadComplete() + mAdapter?.addFooterView(getLayoutInflater(null).inflate(R.layout.not_loading, mRecyclerView?.parent as ViewGroup, false)) + return + } + loadMoreOverride(object : Callback> { + override fun onError(e: Exception) { + //mAdapter.showLoadMoreFailedView();//TODO:Show refresh failed + Toast.makeText(context, "加载失败", Toast.LENGTH_SHORT).show() + } + + override fun onResponse(response: List, totalCount: Int) { + mAdapter?.addData(response) + mTotalCount = totalCount + } + }) + } + + fun refresh() { + if (TextUtils.isEmpty(Entity.accessToken)) return + mSwipeRefreshLayout?.post { mSwipeRefreshLayout?.isRefreshing = true } + mPage = 1 + refreshOverride(object : Callback> { + override fun onError(e: Exception) { + //mAdapter.showLoadMoreFailedView();//TODO:Show refresh failed + Toast.makeText(context, "加载失败", Toast.LENGTH_SHORT).show() + mSwipeRefreshLayout?.isRefreshing = false + } + + override fun onResponse(response: List, totalCount: Int) { + mAdapter?.setNewData(response) + mTotalCount = totalCount + mSwipeRefreshLayout?.isRefreshing = false + } + }) + } + + protected abstract fun loadMoreOverride(callback: Callback>) + protected abstract fun refreshOverride(callback: Callback>) +} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/detail/Comment.java b/app/src/main/java/moe/tlaster/openween/fragment/detail/Comment.java deleted file mode 100644 index 836bc28..0000000 --- a/app/src/main/java/moe/tlaster/openween/fragment/detail/Comment.java +++ /dev/null @@ -1,84 +0,0 @@ -package moe.tlaster.openween.fragment.detail; - -import android.os.Bundle; -import android.support.annotation.Nullable; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.typeface.IIcon; - -import java.util.List; - -import moe.tlaster.openween.adapter.BaseModelAdapter; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.api.comments.Comments; -import moe.tlaster.openween.core.model.comment.CommentListModel; -import moe.tlaster.openween.core.model.comment.CommentModel; -import moe.tlaster.openween.core.model.types.AuthorType; -import moe.tlaster.openween.fragment.WeiboListBase; -import okhttp3.Call; - -/** - * Created by Asahi on 2016/10/29. - */ - -public class Comment extends WeiboListBase { - - private long mID; - - public static Comment create(long id) { - Comment comment = new Comment(); - Bundle bundle = new Bundle(); - bundle.putLong("id", id); - comment.setArguments(bundle); - return comment; - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mID = getArguments().getLong("id"); - } - - @Override - protected BaseQuickAdapter initAdapter() { - return new BaseModelAdapter<>(false); - } - - @Override - protected void loadMoreOverride(Callback> callback) { - Comments.getCommentStatus(mID, 0, ((CommentModel) mAdapter.getData().get(mAdapter.getData().size() - 1)).getID(), mLoadCount, 1, AuthorType.All, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(CommentListModel response, int id) { - response.getComments().remove(0); - callback.onResponse(response.getComments(), response.getTotalNumber()); - } - }); - } - - @Override - protected void refreshOverride(Callback> callback) { - Comments.getCommentStatus(mID, mLoadCount, 1, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(CommentListModel response, int id) { - callback.onResponse(response.getComments(), response.getTotalNumber()); - } - }); - } - - @Override - public IIcon getIcon() { - return GoogleMaterial.Icon.gmd_comment; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/detail/Comment.kt b/app/src/main/java/moe/tlaster/openween/fragment/detail/Comment.kt new file mode 100644 index 0000000..5f37a76 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/fragment/detail/Comment.kt @@ -0,0 +1,74 @@ +package moe.tlaster.openween.fragment.detail + +import android.os.Bundle + +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.IIcon + +import moe.tlaster.openween.adapter.BaseModelAdapter +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.api.comments.Comments +import moe.tlaster.openween.core.model.comment.CommentListModel +import moe.tlaster.openween.core.model.comment.CommentModel +import moe.tlaster.openween.core.model.types.AuthorType +import moe.tlaster.openween.fragment.WeiboListBase +import okhttp3.Call + +/** + * Created by Asahi on 2016/10/29. + */ + +class Comment : WeiboListBase() { + + private var mID: Long = 0 + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + mID = arguments.getLong("id") + } + + override fun initAdapter(): BaseQuickAdapter { + return BaseModelAdapter(false) + } + + override fun loadMoreOverride(callback: WeiboListBase.Callback>) { + Comments.getCommentStatus(mID, max_id = (mAdapter!!.data[mAdapter!!.data.size - 1] as CommentModel).id, count = mLoadCount, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: CommentListModel, id: Int) { + response.comments = response.comments?.subList(1, response.comments?.lastIndex!!) + callback.onResponse(response.comments!!, response.totalNumber) + } + }) + } + + override fun refreshOverride(callback: WeiboListBase.Callback>) { + Comments.getCommentStatus(mID, count = mLoadCount, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: CommentListModel, id: Int) { + callback.onResponse(response.comments!!, response.totalNumber) + } + }) + } + + override val icon: IIcon + get() = GoogleMaterial.Icon.gmd_comment + + companion object { + + fun create(id: Long): Comment { + val comment = Comment() + val bundle = Bundle() + bundle.putLong("id", id) + comment.arguments = bundle + return comment + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/detail/Repost.java b/app/src/main/java/moe/tlaster/openween/fragment/detail/Repost.java deleted file mode 100644 index dc8339d..0000000 --- a/app/src/main/java/moe/tlaster/openween/fragment/detail/Repost.java +++ /dev/null @@ -1,83 +0,0 @@ -package moe.tlaster.openween.fragment.detail; - -import android.os.Bundle; -import android.support.annotation.Nullable; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.typeface.IIcon; - -import java.util.List; - -import moe.tlaster.openween.adapter.BaseModelAdapter; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.model.status.MessageModel; -import moe.tlaster.openween.core.model.status.RepostListModel; -import moe.tlaster.openween.core.model.types.AuthorType; -import moe.tlaster.openween.fragment.WeiboListBase; -import okhttp3.Call; - -/** - * Created by Asahi on 2016/10/29. - */ - -public class Repost extends WeiboListBase { - - private long mID; - - public static Repost create(long id) { - Repost repost = new Repost(); - Bundle bundle = new Bundle(); - bundle.putLong("id", id); - repost.setArguments(bundle); - return repost; - } - - @Override - protected BaseQuickAdapter initAdapter() { - return new BaseModelAdapter<>(false); - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mID = getArguments().getLong("id"); - } - - @Override - protected void loadMoreOverride(Callback> callback) { - moe.tlaster.openween.core.api.statuses.Repost.getRepost(mID, 0, ((MessageModel) mAdapter.getData().get(mAdapter.getData().size() - 1)).getID(), mLoadCount, 1, AuthorType.All, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(RepostListModel response, int id) { - response.getReposts().remove(0); - callback.onResponse(response.getReposts(), response.getTotalNumber()); - } - }); - } - - @Override - protected void refreshOverride(Callback> callback) { - moe.tlaster.openween.core.api.statuses.Repost.getRepost(mID, super.mLoadCount, 1, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(RepostListModel response, int id) { - callback.onResponse(response.getReposts(), response.getTotalNumber()); - } - }); - } - - @Override - public IIcon getIcon() { - return GoogleMaterial.Icon.gmd_reply; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/detail/Repost.kt b/app/src/main/java/moe/tlaster/openween/fragment/detail/Repost.kt new file mode 100644 index 0000000..b3099d1 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/fragment/detail/Repost.kt @@ -0,0 +1,73 @@ +package moe.tlaster.openween.fragment.detail + +import android.os.Bundle + +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.IIcon + +import moe.tlaster.openween.adapter.BaseModelAdapter +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.model.status.MessageModel +import moe.tlaster.openween.core.model.status.RepostListModel +import moe.tlaster.openween.core.model.types.AuthorType +import moe.tlaster.openween.fragment.WeiboListBase +import okhttp3.Call + +/** + * Created by Asahi on 2016/10/29. + */ + +class Repost : WeiboListBase() { + + private var mID: Long = 0 + + override fun initAdapter(): BaseQuickAdapter { + return BaseModelAdapter(false) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + mID = arguments.getLong("id") + } + + override fun loadMoreOverride(callback: WeiboListBase.Callback>) { + moe.tlaster.openween.core.api.statuses.Repost.getRepost(mID, max_id = (mAdapter!!.data[mAdapter!!.data.size - 1] as MessageModel).id, count = mLoadCount, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: RepostListModel, id: Int) { + response.reposts = response.reposts!!.subList(1, response.reposts?.lastIndex!!) + callback.onResponse(response.reposts!!, response.totalNumber) + } + }) + } + + override fun refreshOverride(callback: WeiboListBase.Callback>) { + moe.tlaster.openween.core.api.statuses.Repost.getRepost(mID, count = mLoadCount, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: RepostListModel, id: Int) { + callback.onResponse(response.reposts!!, response.totalNumber) + } + }) + } + + override val icon: IIcon + get() = GoogleMaterial.Icon.gmd_reply + + companion object { + + fun create(id: Long): Repost { + val repost = Repost() + val bundle = Bundle() + bundle.putLong("id", id) + repost.arguments = bundle + return repost + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/main/DirectMessage.java b/app/src/main/java/moe/tlaster/openween/fragment/main/DirectMessage.java deleted file mode 100644 index 9adc64f..0000000 --- a/app/src/main/java/moe/tlaster/openween/fragment/main/DirectMessage.java +++ /dev/null @@ -1,78 +0,0 @@ -package moe.tlaster.openween.fragment.main; - -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.typeface.IIcon; - -import java.util.List; - -import moe.tlaster.openween.R; -import moe.tlaster.openween.adapter.DirectMessageUserListAdapter; -import moe.tlaster.openween.common.controls.Pivot; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.model.directmessage.DirectMessageUserListModel; -import moe.tlaster.openween.core.model.directmessage.DirectMessageUserModel; -import moe.tlaster.openween.fragment.WeiboListBase; -import okhttp3.Call; - -/** - * Created by Tlaster on 2016/9/9. - */ -public class DirectMessage extends WeiboListBase { - - - private int mCursor; - - @Override - protected BaseQuickAdapter initAdapter() { - return new DirectMessageUserListAdapter(); - } - - @Override - protected void loadMoreOverride(Callback> callback) { - moe.tlaster.openween.core.api.directMessage.DirectMessage.getUserList(mLoadCount, mCursor, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(DirectMessageUserListModel response, int id) { - mCursor = Integer.parseInt(response.getNextCursor()); - callback.onResponse(response.getUserList(), response.getTotalNumber()); - } - }); - } - - @Override - protected void refreshOverride(Callback> callback) { - mCursor = 0; - moe.tlaster.openween.core.api.directMessage.DirectMessage.getUserList(mLoadCount, mCursor, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(DirectMessageUserListModel response, int id) { - mCursor = Integer.parseInt(response.getNextCursor()); - callback.onResponse(response.getUserList(), response.getTotalNumber()); - } - }); - } - - - @Override - public IIcon getIcon() { - return GoogleMaterial.Icon.gmd_email; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/main/DirectMessage.kt b/app/src/main/java/moe/tlaster/openween/fragment/main/DirectMessage.kt new file mode 100644 index 0000000..f37a272 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/fragment/main/DirectMessage.kt @@ -0,0 +1,66 @@ +package moe.tlaster.openween.fragment.main + +import android.os.Bundle +import android.support.v4.app.Fragment +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup + +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.IIcon + +import moe.tlaster.openween.R +import moe.tlaster.openween.adapter.DirectMessageUserListAdapter +import moe.tlaster.openween.common.controls.Pivot +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.model.directmessage.DirectMessageUserListModel +import moe.tlaster.openween.core.model.directmessage.DirectMessageUserModel +import moe.tlaster.openween.fragment.WeiboListBase +import okhttp3.Call + +/** + * Created by Tlaster on 2016/9/9. + */ +class DirectMessage : WeiboListBase() { + + + private var mCursor: Int = 0 + + override fun initAdapter(): BaseQuickAdapter { + return DirectMessageUserListAdapter() + } + + override fun loadMoreOverride(callback: WeiboListBase.Callback>) { + moe.tlaster.openween.core.api.directMessage.DirectMessage.getUserList(mLoadCount, mCursor, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: DirectMessageUserListModel, id: Int) { + mCursor = Integer.parseInt(response.nextCursor) + callback.onResponse(response.userList!!, response.totalNumber) + } + }) + } + + override fun refreshOverride(callback: WeiboListBase.Callback>) { + mCursor = 0 + moe.tlaster.openween.core.api.directMessage.DirectMessage.getUserList(mLoadCount, mCursor, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: DirectMessageUserListModel, id: Int) { + mCursor = Integer.parseInt(response.nextCursor) + callback.onResponse(response.userList!!, response.totalNumber) + } + }) + } + + + override val icon: IIcon + get() = GoogleMaterial.Icon.gmd_email +} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/main/Message.java b/app/src/main/java/moe/tlaster/openween/fragment/main/Message.java deleted file mode 100644 index bf8d160..0000000 --- a/app/src/main/java/moe/tlaster/openween/fragment/main/Message.java +++ /dev/null @@ -1,155 +0,0 @@ -package moe.tlaster.openween.fragment.main; - -import android.support.v7.widget.RecyclerView; -import android.view.View; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.listener.OnItemChildClickListener; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.typeface.IIcon; - -import java.util.ArrayList; -import java.util.List; -import com.annimon.stream.*; - -import moe.tlaster.openween.adapter.BaseModelAdapter; -import moe.tlaster.openween.common.helpers.InvalidAccessTokenException; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.common.helpers.Reverse; -import moe.tlaster.openween.core.api.comments.Comments; -import moe.tlaster.openween.core.api.remind.Remind; -import moe.tlaster.openween.core.api.statuses.Mentions; -import moe.tlaster.openween.core.model.BaseModel; -import moe.tlaster.openween.core.model.comment.CommentListModel; -import moe.tlaster.openween.core.model.status.MessageListModel; -import moe.tlaster.openween.core.model.types.RemindType; -import moe.tlaster.openween.fragment.WeiboListBase; -import okhttp3.Call; -/** - * Created by Tlaster on 2016/9/9. - */ -public class Message extends WeiboListBase { - - private long mMentionID; - private long mCommentID; - private long mCommentMentionsID; - - @Override - protected void refreshOverride(Callback> callback) { //Fucking JAVA - final List mention = new ArrayList<>(); - final int[] mentionNumber = {0}; - final List comment = new ArrayList<>(); - final int[] commentNumber = {0}; - final List commentMentions = new ArrayList<>(); - final int[] commentMentionsNumber = {0}; - Remind.clearUnread(RemindType.MentionStatus); - Mentions.getMentions(mLoadCount, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - @Override - public void onResponse(MessageListModel response, int id) { - mention.addAll(response.getStatuses()); - mentionNumber[0] += response.getTotalNumber(); - if (response.getStatuses().size() > 0) - mMentionID = response.getStatuses().get(response.getStatuses().size() - 1).getID(); - Remind.clearUnread(RemindType.Comment); - Comments.getCommentToMe(mLoadCount, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - @Override - public void onResponse(CommentListModel response, int id) { - comment.addAll(response.getComments()); - commentNumber[0] = response.getTotalNumber(); - if (response.getComments().size() > 0) - mCommentID = response.getComments().get(response.getComments().size() - 1).getID(); - Remind.clearUnread(RemindType.MentionComment); - Comments.getCommentMentions(mLoadCount, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - @Override - public void onResponse(CommentListModel response, int id) { - commentMentions.addAll(response.getComments()); - commentMentionsNumber[0] = response.getTotalNumber(); - if (response.getComments().size() > 0) - mCommentMentionsID = response.getComments().get(response.getComments().size() - 1).getID(); - callback.onResponse(Stream.concat(Stream.concat(Stream.of(mention), Stream.of(comment)), Stream.of(commentMentions)) - .sortBy(BaseModel::getCreatedDate) - .custom(new Reverse<>()).collect(Collectors.toList()), - mentionNumber[0] + commentNumber[0] + commentMentionsNumber[0]); - } - }); - } - }); - } - }); - - } - - @Override - protected void loadMoreOverride(Callback> callback) { - - final List mention = new ArrayList<>(); - final int[] mentionNumber = {0}; - final List comment = new ArrayList<>(); - final int[] commentNumber = {0}; - final List commentMentions = new ArrayList<>(); - final int[] commentMentionsNumber = {0}; - Mentions.getMentions(mMentionID, mLoadCount, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - - @Override - public void onResponse(MessageListModel response, int id) { - mention.addAll(response.getStatuses()); - mentionNumber[0] += response.getTotalNumber(); - if (response.getStatuses().size() > 0) - mMentionID = response.getStatuses().get(response.getStatuses().size() - 1).getID(); - Comments.getCommentToMe(mCommentID, mLoadCount, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - - @Override - public void onResponse(CommentListModel response, int id) { - comment.addAll(response.getComments()); - commentNumber[0] = response.getTotalNumber(); - if (response.getComments().size() > 0) - mCommentID = response.getComments().get(response.getComments().size() - 1).getID(); - Comments.getCommentMentions(mCommentMentionsID, mLoadCount, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - - } - - @Override - public void onResponse(CommentListModel response, int id) { - commentMentions.addAll(response.getComments()); - commentMentionsNumber[0] = response.getTotalNumber(); - if (response.getComments().size() > 0) - mCommentMentionsID = response.getComments().get(response.getComments().size() - 1).getID(); - callback.onResponse(Stream.concat(Stream.concat(Stream.of(mention), Stream.of(comment)), Stream.of(commentMentions)) - .sortBy(BaseModel::getCreatedDate) - .custom(new Reverse<>()).collect(Collectors.toList()), - mentionNumber[0] + commentNumber[0] + commentMentionsNumber[0]); - } - }); - } - }); - } - }); - } - - @Override - public IIcon getIcon() { - return GoogleMaterial.Icon.gmd_forum; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/main/Message.kt b/app/src/main/java/moe/tlaster/openween/fragment/main/Message.kt new file mode 100644 index 0000000..7508c40 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/fragment/main/Message.kt @@ -0,0 +1,140 @@ +package moe.tlaster.openween.fragment.main + +import android.support.v7.widget.RecyclerView +import android.view.View + +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.listener.OnItemChildClickListener +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.IIcon + +import java.util.ArrayList +import com.chad.library.adapter.base.BaseViewHolder + +import moe.tlaster.openween.adapter.BaseModelAdapter +import moe.tlaster.openween.common.helpers.InvalidAccessTokenException +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.api.comments.Comments +import moe.tlaster.openween.core.api.remind.Remind +import moe.tlaster.openween.core.api.statuses.Mentions +import moe.tlaster.openween.core.model.BaseModel +import moe.tlaster.openween.core.model.comment.CommentListModel +import moe.tlaster.openween.core.model.status.MessageListModel +import moe.tlaster.openween.core.model.status.MessageModel +import moe.tlaster.openween.core.model.types.RemindType +import moe.tlaster.openween.fragment.WeiboListBase +import okhttp3.Call + +/** + * Created by Tlaster on 2016/9/9. + */ +class Message : WeiboListBase() { + + private var mMentionID: Long = 0 + private var mCommentID: Long = 0 + private var mCommentMentionsID: Long = 0 + + override fun initAdapter(): BaseQuickAdapter { + return BaseModelAdapter() + } + override fun refreshOverride(callback: WeiboListBase.Callback>) { + val mention = ArrayList() + val mentionNumber = intArrayOf(0) + val comment = ArrayList() + val commentNumber = intArrayOf(0) + val commentMentions = ArrayList() + val commentMentionsNumber = intArrayOf(0) + Remind.clearUnread(RemindType.MentionStatus) + Mentions.getMentions(count = mLoadCount, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: MessageListModel, id: Int) { + mention.addAll(response.statuses!!) + mentionNumber[0] += response.totalNumber + if (response.statuses!!.isNotEmpty()) + mMentionID = response.statuses!![response.statuses!!.size - 1].id + Remind.clearUnread(RemindType.Comment) + Comments.getCommentToMe(count = mLoadCount, callBack = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: CommentListModel, id: Int) { + comment.addAll(response.comments!!) + commentNumber[0] = response.totalNumber + if (response.comments!!.isNotEmpty()) + mCommentID = response.comments!![response.comments!!.size - 1].id + Remind.clearUnread(RemindType.MentionComment) + Comments.getCommentMentions(count = mLoadCount, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: CommentListModel, id: Int) { + commentMentions.addAll(response.comments!!) + commentMentionsNumber[0] = response.totalNumber + if (response.comments!!.isNotEmpty()) + mCommentMentionsID = response.comments!![response.comments!!.size - 1].id + callback.onResponse((mention + comment + commentMentions).sortedByDescending { it.createdDate }, mentionNumber[0] + commentNumber[0] + commentMentionsNumber[0]) + } + }) + } + }) + } + }) + + } + + override fun loadMoreOverride(callback: WeiboListBase.Callback>) { + + val mention = ArrayList() + val mentionNumber = intArrayOf(0) + val comment = ArrayList() + val commentNumber = intArrayOf(0) + val commentMentions = ArrayList() + val commentMentionsNumber = intArrayOf(0) + Mentions.getMentions(max_id = mMentionID, count = mLoadCount, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: MessageListModel, id: Int) { + mention.addAll(response.statuses!!) + mentionNumber[0] += response.totalNumber + if (response.statuses!!.isNotEmpty()) + mMentionID = response.statuses!![response.statuses!!.size - 1].id + Comments.getCommentToMe(max_id = mCommentID, count = mLoadCount, callBack = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: CommentListModel, id: Int) { + comment.addAll(response.comments!!) + commentNumber[0] = response.totalNumber + if (response.comments!!.isNotEmpty()) + mCommentID = response.comments!![response.comments!!.size - 1].id + Comments.getCommentMentions(max_id = mCommentMentionsID, count = mLoadCount, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: CommentListModel, id: Int) { + commentMentions.addAll(response.comments!!) + commentMentionsNumber[0] = response.totalNumber + if (response.comments!!.isNotEmpty()) + mCommentMentionsID = response.comments!![response.comments!!.size - 1].id + callback.onResponse((mention + comment + commentMentions).sortedByDescending { it.createdDate }, mentionNumber[0] + commentNumber[0] + commentMentionsNumber[0]) + + } + }) + } + }) + } + }) + } + + override val icon: IIcon + get() = GoogleMaterial.Icon.gmd_forum +} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/main/Timeline.java b/app/src/main/java/moe/tlaster/openween/fragment/main/Timeline.java deleted file mode 100644 index 9dd1fc2..0000000 --- a/app/src/main/java/moe/tlaster/openween/fragment/main/Timeline.java +++ /dev/null @@ -1,81 +0,0 @@ -package moe.tlaster.openween.fragment.main; - -import android.support.v7.widget.RecyclerView; -import android.view.View; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.listener.OnItemChildClickListener; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.typeface.IIcon; - -import java.util.List; - -import moe.tlaster.openween.R; -import moe.tlaster.openween.adapter.BaseModelAdapter; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.api.friendships.Groups; -import moe.tlaster.openween.core.api.statuses.Home; -import moe.tlaster.openween.core.model.status.MessageListModel; -import moe.tlaster.openween.core.model.status.MessageModel; -import moe.tlaster.openween.fragment.WeiboListBase; -import okhttp3.Call; - -/** - * Created by Tlaster on 2016/9/9. - */ -public class Timeline extends WeiboListBase { - - - private long mGroupID = -1; - - @Override - protected void loadMoreOverride(Callback> callback) { - JsonCallback jsonCallback = new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(MessageListModel response, int id) { - response.getStatuses().remove(0); - callback.onResponse(response.getStatuses(), response.getTotalNumber()); - } - }; - if (mGroupID != -1) { - Groups.getGroupTimeline(String.valueOf(mGroupID), ((MessageModel) mAdapter.getData().get(mAdapter.getData().size() - 1)).getID(), mLoadCount, jsonCallback); - } else { - Home.getTimeline(mLoadCount, ((MessageModel) mAdapter.getData().get(mAdapter.getData().size() - 1)).getID(),jsonCallback); - } - } - - @Override - protected void refreshOverride(Callback> callback) { - JsonCallback jsonCallback = new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(MessageListModel response, int id) { - callback.onResponse(response.getStatuses(), response.getTotalNumber()); - } - }; - if (mGroupID != -1) { - Groups.getGroupTimeline(String.valueOf(mGroupID), mLoadCount, jsonCallback); - } else { - Home.getTimeline(mLoadCount, jsonCallback); - } - } - - @Override - public IIcon getIcon() { - return GoogleMaterial.Icon.gmd_home; - } - - public void toGroup(long id) { - mGroupID = id; - refresh(); - } -} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/main/Timeline.kt b/app/src/main/java/moe/tlaster/openween/fragment/main/Timeline.kt new file mode 100644 index 0000000..c29d811 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/fragment/main/Timeline.kt @@ -0,0 +1,75 @@ +package moe.tlaster.openween.fragment.main + +import android.support.v7.widget.RecyclerView +import android.view.View + +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder +import com.chad.library.adapter.base.listener.OnItemChildClickListener +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.IIcon + +import moe.tlaster.openween.R +import moe.tlaster.openween.adapter.BaseModelAdapter +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.api.friendships.Groups +import moe.tlaster.openween.core.api.statuses.Home +import moe.tlaster.openween.core.model.status.MessageListModel +import moe.tlaster.openween.core.model.status.MessageModel +import moe.tlaster.openween.fragment.WeiboListBase +import okhttp3.Call + +/** + * Created by Tlaster on 2016/9/9. + */ +class Timeline : WeiboListBase() { + + + override fun initAdapter(): BaseQuickAdapter { + return BaseModelAdapter() + } + private var mGroupID: Long = -1 + + override fun loadMoreOverride(callback: WeiboListBase.Callback>) { + val jsonCallback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: MessageListModel, id: Int) { + response.statuses = response.statuses!!.subList(1, response.statuses!!.lastIndex) + callback.onResponse(response.statuses!!, response.totalNumber) + } + } + if (mGroupID != -1L) { + Groups.getGroupTimeline(mGroupID.toString(), max_id = (mAdapter!!.data[mAdapter!!.data.size - 1] as MessageModel).id, count = mLoadCount, callback = jsonCallback) + } else { + Home.getTimeline(count = mLoadCount, max_id = (mAdapter!!.data[mAdapter!!.data.size - 1] as MessageModel).id, callback = jsonCallback) + } + } + + override fun refreshOverride(callback: WeiboListBase.Callback>) { + val jsonCallback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: MessageListModel, id: Int) { + callback.onResponse(response.statuses!!, response.totalNumber) + } + } + if (mGroupID != -1L) { + Groups.getGroupTimeline(mGroupID.toString(), count = mLoadCount, callback = jsonCallback) + } else { + Home.getTimeline(mLoadCount, callback = jsonCallback) + } + } + + override val icon: IIcon + get() = GoogleMaterial.Icon.gmd_home + + fun toGroup(id: Long) { + mGroupID = id + refresh() + } +} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/user/Follower.java b/app/src/main/java/moe/tlaster/openween/fragment/user/Follower.java deleted file mode 100644 index 1457a08..0000000 --- a/app/src/main/java/moe/tlaster/openween/fragment/user/Follower.java +++ /dev/null @@ -1,92 +0,0 @@ -package moe.tlaster.openween.fragment.user; - -import android.os.Bundle; -import android.support.annotation.Nullable; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.typeface.IIcon; - -import java.util.List; - -import moe.tlaster.openween.adapter.UserListAdapter; -import moe.tlaster.openween.common.StaticResource; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.api.friendships.Friends; -import moe.tlaster.openween.core.api.remind.Remind; -import moe.tlaster.openween.core.model.types.RemindType; -import moe.tlaster.openween.core.model.user.UserListModel; -import moe.tlaster.openween.core.model.user.UserModel; -import moe.tlaster.openween.fragment.WeiboListBase; -import okhttp3.Call; - -/** - * Created by Asahi on 2016/11/3. - */ - -public class Follower extends WeiboListBase { - - private long mID; - private int mCursor; - - - public static Follower create(long id) { - Follower follower = new Follower(); - Bundle bundle = new Bundle(); - bundle.putLong("id", id); - follower.setArguments(bundle); - return follower; - } - - @Override - protected BaseQuickAdapter initAdapter() { - return new UserListAdapter(); - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mID = getArguments().getLong("id"); - } - - @Override - protected void loadMoreOverride(Callback> callback) { - Friends.getFollowers(mID, mLoadCount, mCursor, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(UserListModel response, int id) { - mCursor = Integer.parseInt(response.getNextCursor()); - callback.onResponse(response.getUsers(), response.getTotalNumber()); - } - }); - } - - @Override - protected void refreshOverride(Callback> callback) { - if (mID == StaticResource.getUid()) - Remind.clearUnread(RemindType.Follower); - mCursor = 0; - Friends.getFollowers(mID, mLoadCount, mCursor, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(UserListModel response, int id) { - mCursor = Integer.parseInt(response.getNextCursor()); - callback.onResponse(response.getUsers(), response.getTotalNumber()); - } - }); - } - - @Override - public IIcon getIcon() { - return GoogleMaterial.Icon.gmd_people; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/user/Follower.kt b/app/src/main/java/moe/tlaster/openween/fragment/user/Follower.kt new file mode 100644 index 0000000..d00384c --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/fragment/user/Follower.kt @@ -0,0 +1,82 @@ +package moe.tlaster.openween.fragment.user + +import android.os.Bundle + +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.IIcon + +import moe.tlaster.openween.adapter.UserListAdapter +import moe.tlaster.openween.common.StaticResource +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.api.friendships.Friends +import moe.tlaster.openween.core.api.remind.Remind +import moe.tlaster.openween.core.model.types.RemindType +import moe.tlaster.openween.core.model.user.UserListModel +import moe.tlaster.openween.core.model.user.UserModel +import moe.tlaster.openween.fragment.WeiboListBase +import okhttp3.Call + +/** + * Created by Asahi on 2016/11/3. + */ + +class Follower : WeiboListBase() { + + private var mID: Long = 0 + private var mCursor: Int = 0 + + override fun initAdapter(): BaseQuickAdapter { + return UserListAdapter() + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + mID = arguments.getLong("id") + } + + override fun loadMoreOverride(callback: WeiboListBase.Callback>) { + Friends.getFollowers(mID, mLoadCount, mCursor, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: UserListModel, id: Int) { + mCursor = Integer.parseInt(response.nextCursor) + callback.onResponse(response.users!!, response.totalNumber) + } + }) + } + + override fun refreshOverride(callback: WeiboListBase.Callback>) { + if (mID == StaticResource.uid) + Remind.clearUnread(RemindType.Follower) + mCursor = 0 + Friends.getFollowers(mID, mLoadCount, mCursor, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: UserListModel, id: Int) { + mCursor = Integer.parseInt(response.nextCursor) + callback.onResponse(response.users!!, response.totalNumber) + } + }) + } + + override val icon: IIcon + get() = GoogleMaterial.Icon.gmd_people + + companion object { + + + fun create(id: Long): Follower { + val follower = Follower() + val bundle = Bundle() + bundle.putLong("id", id) + follower.arguments = bundle + return follower + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/user/Following.java b/app/src/main/java/moe/tlaster/openween/fragment/user/Following.java deleted file mode 100644 index 27a54e0..0000000 --- a/app/src/main/java/moe/tlaster/openween/fragment/user/Following.java +++ /dev/null @@ -1,88 +0,0 @@ -package moe.tlaster.openween.fragment.user; - -import android.os.Bundle; -import android.support.annotation.Nullable; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.typeface.IIcon; - -import java.util.List; - -import moe.tlaster.openween.adapter.UserListAdapter; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.api.friendships.Friends; -import moe.tlaster.openween.core.model.user.UserListModel; -import moe.tlaster.openween.core.model.user.UserModel; -import moe.tlaster.openween.fragment.WeiboListBase; -import okhttp3.Call; - -/** - * Created by Asahi on 2016/11/3. - */ - -public class Following extends WeiboListBase { - - - private long mID; - private int mCursor; - - - public static Following create(long id) { - Following following = new Following(); - Bundle bundle = new Bundle(); - bundle.putLong("id", id); - following.setArguments(bundle); - return following; - } - - @Override - protected BaseQuickAdapter initAdapter() { - return new UserListAdapter(); - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mID = getArguments().getLong("id"); - } - - @Override - protected void loadMoreOverride(Callback> callback) { - Friends.getFriends(mID, mLoadCount, mCursor, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(UserListModel response, int id) { - mCursor = Integer.parseInt(response.getNextCursor()); - callback.onResponse(response.getUsers(), response.getTotalNumber()); - } - }); - } - - @Override - protected void refreshOverride(Callback> callback) { - mCursor = 0; - Friends.getFriends(mID, mLoadCount, mCursor, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(UserListModel response, int id) { - mCursor = Integer.parseInt(response.getNextCursor()); - callback.onResponse(response.getUsers(), response.getTotalNumber()); - } - }); - } - - @Override - public IIcon getIcon() { - return GoogleMaterial.Icon.gmd_people; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/user/Following.kt b/app/src/main/java/moe/tlaster/openween/fragment/user/Following.kt new file mode 100644 index 0000000..37d2601 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/fragment/user/Following.kt @@ -0,0 +1,78 @@ +package moe.tlaster.openween.fragment.user + +import android.os.Bundle + +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.IIcon + +import moe.tlaster.openween.adapter.UserListAdapter +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.api.friendships.Friends +import moe.tlaster.openween.core.model.user.UserListModel +import moe.tlaster.openween.core.model.user.UserModel +import moe.tlaster.openween.fragment.WeiboListBase +import okhttp3.Call + +/** + * Created by Asahi on 2016/11/3. + */ + +class Following : WeiboListBase() { + + + private var mID: Long = 0 + private var mCursor: Int = 0 + + override fun initAdapter(): BaseQuickAdapter { + return UserListAdapter() + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + mID = arguments.getLong("id") + } + + override fun loadMoreOverride(callback: WeiboListBase.Callback>) { + Friends.getFriends(mID, mLoadCount, mCursor, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: UserListModel, id: Int) { + mCursor = Integer.parseInt(response.nextCursor) + callback.onResponse(response.users!!, response.totalNumber) + } + }) + } + + override fun refreshOverride(callback: WeiboListBase.Callback>) { + mCursor = 0 + Friends.getFriends(mID, mLoadCount, mCursor, object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: UserListModel, id: Int) { + mCursor = Integer.parseInt(response.nextCursor) + callback.onResponse(response.users!!, response.totalNumber) + } + }) + } + + override val icon: IIcon + get() = GoogleMaterial.Icon.gmd_people + + companion object { + + + fun create(id: Long): Following { + val following = Following() + val bundle = Bundle() + bundle.putLong("id", id) + following.arguments = bundle + return following + } + } +} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/user/Timeline.java b/app/src/main/java/moe/tlaster/openween/fragment/user/Timeline.java deleted file mode 100644 index c8d4783..0000000 --- a/app/src/main/java/moe/tlaster/openween/fragment/user/Timeline.java +++ /dev/null @@ -1,79 +0,0 @@ -package moe.tlaster.openween.fragment.user; - -import android.os.Bundle; -import android.support.annotation.Nullable; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.mikepenz.google_material_typeface_library.GoogleMaterial; -import com.mikepenz.iconics.typeface.IIcon; - -import java.util.List; - -import moe.tlaster.openween.adapter.BaseModelAdapter; -import moe.tlaster.openween.common.helpers.JsonCallback; -import moe.tlaster.openween.core.api.statuses.UserTimeline; -import moe.tlaster.openween.core.model.status.MessageListModel; -import moe.tlaster.openween.core.model.status.MessageModel; -import moe.tlaster.openween.fragment.WeiboListBase; -import moe.tlaster.openween.fragment.detail.Repost; -import okhttp3.Call; - -/** - * Created by Asahi on 2016/11/3. - */ - -public class Timeline extends WeiboListBase { - - private long mID; - - public static Timeline create(long id) { - Timeline timeline = new Timeline(); - Bundle bundle = new Bundle(); - bundle.putLong("id", id); - timeline.setArguments(bundle); - return timeline; - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mID = getArguments().getLong("id"); - } - - - @Override - protected void loadMoreOverride(Callback> callback) { - UserTimeline.getUserTimeline(mID, mLoadCount, ((MessageModel) mAdapter.getData().get(mAdapter.getData().size() - 1)).getID(), new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(MessageListModel response, int id) { - response.getStatuses().remove(0); - callback.onResponse(response.getStatuses(), response.getTotalNumber()); - } - }); - } - - @Override - protected void refreshOverride(Callback> callback) { - UserTimeline.getUserTimeline(mID, mLoadCount, new JsonCallback() { - @Override - public void onError(Call call, Exception e, int id) { - callback.onError(e); - } - - @Override - public void onResponse(MessageListModel response, int id) { - callback.onResponse(response.getStatuses(), response.getTotalNumber()); - } - }); - } - - @Override - public IIcon getIcon() { - return GoogleMaterial.Icon.gmd_home; - } -} diff --git a/app/src/main/java/moe/tlaster/openween/fragment/user/Timeline.kt b/app/src/main/java/moe/tlaster/openween/fragment/user/Timeline.kt new file mode 100644 index 0000000..b0e05e2 --- /dev/null +++ b/app/src/main/java/moe/tlaster/openween/fragment/user/Timeline.kt @@ -0,0 +1,76 @@ +package moe.tlaster.openween.fragment.user + +import android.os.Bundle + +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.IIcon + +import moe.tlaster.openween.adapter.BaseModelAdapter +import moe.tlaster.openween.adapter.UserListAdapter +import moe.tlaster.openween.common.helpers.JsonCallback +import moe.tlaster.openween.core.api.statuses.UserTimeline +import moe.tlaster.openween.core.model.status.MessageListModel +import moe.tlaster.openween.core.model.status.MessageModel +import moe.tlaster.openween.core.model.user.UserModel +import moe.tlaster.openween.fragment.WeiboListBase +import moe.tlaster.openween.fragment.detail.Repost +import okhttp3.Call + +/** + * Created by Asahi on 2016/11/3. + */ + +class Timeline : WeiboListBase() { + + private var mID: Long = 0 + + override fun initAdapter(): BaseQuickAdapter { + return BaseModelAdapter() + } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + mID = arguments.getLong("id") + } + + + override fun loadMoreOverride(callback: WeiboListBase.Callback>) { + UserTimeline.getUserTimeline(mID, count = mLoadCount, max_id = (mAdapter!!.data[mAdapter!!.data.size - 1] as MessageModel).id, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: MessageListModel, id: Int) { + response.statuses = response.statuses!!.subList(1, response.statuses!!.lastIndex) + callback.onResponse(response.statuses!!, response.totalNumber) + } + }) + } + + override fun refreshOverride(callback: WeiboListBase.Callback>) { + UserTimeline.getUserTimeline(mID, count = mLoadCount, callback = object : JsonCallback() { + override fun onError(call: Call, e: Exception, id: Int) { + callback.onError(e) + } + + override fun onResponse(response: MessageListModel, id: Int) { + callback.onResponse(response.statuses!!, response.totalNumber) + } + }) + } + + override val icon: IIcon + get() = GoogleMaterial.Icon.gmd_home + + companion object { + + fun create(id: Long): Timeline { + val timeline = Timeline() + val bundle = Bundle() + bundle.putLong("id", id) + timeline.arguments = bundle + return timeline + } + } +} diff --git a/build.gradle b/build.gradle index f760741..3932ba3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.0.5-2' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -16,6 +18,7 @@ allprojects { repositories { jcenter() maven { url "https://jitpack.io" } + maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } //maven {url "https://clojars.org/repo/"} } }