-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 859026a
Showing
51 changed files
with
1,303 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
apply plugin: 'kotlin-android' | ||
|
||
apply plugin: 'kotlin-android-extensions' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
defaultConfig { | ||
applicationId "com.sunil.twitterkotlinmvvm" | ||
minSdkVersion 16 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
dataBinding { | ||
enabled = true | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" | ||
implementation 'com.android.support:appcompat-v7:26.1.0' | ||
implementation 'com.android.support.constraint:constraint-layout:1.0.2' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.1' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' | ||
|
||
// RX | ||
compile "io.reactivex.rxjava2:rxjava:$rxjava2_version" | ||
compile "io.reactivex.rxjava2:rxandroid:$rxjava2_version" | ||
|
||
compile "com.android.support:recyclerview-v7:$support_version" | ||
compile "com.android.support:cardview-v7:$support_version" | ||
compile "com.android.support:design:$support_version" | ||
|
||
compile 'com.twitter.sdk.android:twitter-core:3.1.1' | ||
compile 'com.squareup.picasso:picasso:2.5.2' | ||
|
||
kapt 'com.android.databinding:compiler:2.3.2' | ||
} | ||
|
||
kapt { | ||
generateStubs = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/sunil/twitterkotlinmvvm/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.sunil.twitterkotlinmvvm | ||
|
||
import android.support.test.InstrumentationRegistry | ||
import android.support.test.runner.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getTargetContext() | ||
assertEquals("com.sunil.twitterkotlinmvvm", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.sunil.twitterkotlinmvvm"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:name=".MainApplication" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity" | ||
android:screenOrientation="portrait"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".ui.TimelineActivity" | ||
android:screenOrientation="portrait"/> | ||
</application> | ||
|
||
</manifest> |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/sunil/twitterkotlinmvvm/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.sunil.twitterkotlinmvvm | ||
|
||
import android.content.Intent | ||
import android.support.v7.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.widget.Toast | ||
import com.sunil.twitterkotlinmvvm.ui.TimelineActivity | ||
import com.twitter.sdk.android.core.Callback | ||
import com.twitter.sdk.android.core.Result | ||
import com.twitter.sdk.android.core.TwitterException | ||
import com.twitter.sdk.android.core.TwitterSession | ||
import com.twitter.sdk.android.core.identity.TwitterLoginButton | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
var loginButton: TwitterLoginButton? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
loginButton = findViewById(R.id.loginButton) | ||
loginButton!!.callback = object : Callback<TwitterSession>() { | ||
override fun success(result: Result<TwitterSession>) { | ||
startActivity(Intent(this@MainActivity, TimelineActivity::class.java)) | ||
finish() | ||
} | ||
|
||
override fun failure(exception: TwitterException) { | ||
Toast.makeText(applicationContext, exception.message, Toast.LENGTH_LONG).show() | ||
} | ||
} | ||
} | ||
|
||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { | ||
super.onActivityResult(requestCode, resultCode, data) | ||
loginButton!!.onActivityResult(requestCode, resultCode, data) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/sunil/twitterkotlinmvvm/MainApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.sunil.twitterkotlinmvvm | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import com.twitter.sdk.android.core.Twitter | ||
import com.twitter.sdk.android.core.TwitterAuthConfig | ||
import com.twitter.sdk.android.core.TwitterConfig | ||
|
||
/** | ||
* Created by sunil on 05-11-2017. | ||
*/ | ||
class MainApplication : Application() { | ||
|
||
init { | ||
instance = this | ||
} | ||
|
||
companion object { | ||
private var instance: MainApplication? = null | ||
|
||
fun applicationContext() : Context { | ||
return instance!!.applicationContext | ||
} | ||
} | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
Twitter.initialize(TwitterConfig.Builder(this).twitterAuthConfig | ||
(TwitterAuthConfig(getString(R.string.com_twitter_sdk_android_CONSUMER_KEY), | ||
getString(R.string.com_twitter_sdk_android_CONSUMER_SECRET))).build()) | ||
|
||
val context: Context = MainApplication.applicationContext() | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/sunil/twitterkotlinmvvm/ui/TimelineActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.sunil.twitterkotlinmvvm.ui | ||
|
||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
import android.support.v7.widget.Toolbar | ||
import com.sunil.twitterkotlinmvvm.R | ||
|
||
/** | ||
* Created by sunil on 05-11-2017. | ||
*/ | ||
class TimelineActivity : AppCompatActivity() { | ||
|
||
private val TAG: String = javaClass.simpleName | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_timeline) | ||
|
||
val toolbar = findViewById<Toolbar>(R.id.toolbar) | ||
|
||
setSupportActionBar(toolbar) | ||
|
||
if (savedInstanceState == null){ | ||
supportFragmentManager.beginTransaction() | ||
.replace(R.id.main_container, TimelineFragment.newInstance("Oi")) | ||
.commit() | ||
} | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/sunil/twitterkotlinmvvm/ui/TimelineAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ccom.sunil.twitterkotlinmvvm.ui | ||
|
||
import android.content.Context | ||
import android.databinding.DataBindingUtil | ||
import android.support.v7.widget.RecyclerView | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import com.squareup.picasso.Picasso | ||
import com.sunil.twitterkotlinmvvm.MainApplication | ||
import com.sunil.twitterkotlinmvvm.R | ||
import com.sunil.twitterkotlinmvvm.databinding.TimelineItemBinding | ||
import com.sunil.twitterkotlinmvvm.viewmodel.ProfileViewModel | ||
import com.sunil.twitterkotlinmvvm.viewmodel.TimelineItemViewModel | ||
import com.twitter.sdk.android.core.models.Tweet | ||
|
||
|
||
/** | ||
* Created by sunil on 05-11-2017. | ||
*/ | ||
class TimelineAdapter(var items: List<Tweet>) : RecyclerView.Adapter<TimelineAdapter.TimelineViewHolder>() { | ||
|
||
val TAG = javaClass.simpleName | ||
|
||
constructor() : this(emptyList()) | ||
|
||
// Provide a reference to the views for each data item | ||
class TimelineViewHolder(var view: TimelineItemBinding) : RecyclerView.ViewHolder(view.root) | ||
|
||
override fun onBindViewHolder(holder: TimelineViewHolder?, position: Int) { | ||
// - get element from your dataset at this position & replace the contents of the view with that element | ||
holder!!.view.vm.tweet.set(items[position].text) | ||
holder.view.vm.user.set(items[position].user.screenName) | ||
val profileViewModel = ProfileViewModel(MainApplication.applicationContext(), items[position].user.profileImageUrl) | ||
holder.view.vm.imageUrl.set(profileViewModel.profileImage!!.get()) | ||
holder.view.vm.userScreenName.set(String.format("@%s", items[position].user.screenName)) | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): TimelineAdapter.TimelineViewHolder { | ||
val inflater = parent!!.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater | ||
val binding: TimelineItemBinding = DataBindingUtil.inflate(inflater, R.layout.timeline_item, parent, false) | ||
binding.vm = TimelineItemViewModel() | ||
|
||
return TimelineViewHolder(binding) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return items.size | ||
} | ||
|
||
fun updateItems(tweets: List<Tweet>){ | ||
items = emptyList() | ||
items = tweets | ||
notifyDataSetChanged() | ||
} | ||
|
||
} |
Oops, something went wrong.