Skip to content

Commit

Permalink
Merge pull request #32 from umbum/develop
Browse files Browse the repository at this point in the history
Release v1.0.0
  • Loading branch information
umbum authored Aug 17, 2019
2 parents 77729a8 + f15619f commit 8ac8d1e
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 51 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
/build
/captures
.externalNativeBuild
.idea
.idea
gradle.properties
*.keystore
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dist: trusty
android:
components:
- build-tools-28.0.3
- android-26
- android-28
- extra

script:
Expand Down
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ buildProperties {
}

android {
compileSdkVersion 26
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.tistory.umbum.github_issue_widget_app"
minSdkVersion 21
targetSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
buildConfigString "CLIENT_SECRET", (buildProperties.secrets['github_client_secret'] | buildProperties.notThere['github_client_secret']).string
Expand All @@ -33,7 +33,7 @@ android {
}
signingConfigs {
release {
storeFile file("/Users/umbum/Untitled")
storeFile file("github_issue_widget.keystore")
storePassword((buildProperties.secrets['android_store_password'] | buildProperties.notThere['android_store_password']).string)
keyAlias((buildProperties.secrets['android_key_alias'] | buildProperties.notThere['android_key_alias']).string)
keyPassword((buildProperties.secrets['android_store_password'] | buildProperties.notThere['android_store_password']).string)
Expand All @@ -54,10 +54,10 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
Expand All @@ -66,8 +66,8 @@ dependencies {
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
implementation "com.android.support:customtabs:26.1.0"
implementation "com.android.support:recyclerview-v7:26.1.0"
implementation "com.android.support:customtabs:28.0.0"
implementation "com.android.support:recyclerview-v7:28.0.0"
kapt "com.android.databinding:compiler:$android_plugin_version"
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
implementation "io.reactivex.rxjava2:rxjava:2.2.10"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tistory.umbum.github_issue_widget_app

const val DBG_TAG = "UMBUMDBG"
const val CLIENT_ID = BuildConfig.CLIENT_ID
const val CLIENT_SECRET = BuildConfig.CLIENT_SECRET
const val REDIRECT_URI = BuildConfig.REDIRECT_URI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@ import com.tistory.umbum.github_issue_widget_app.ALL_ISSUES_TEXT

class UserSelectedRepository(private val context: Context) {
val TAG = this::class.java.simpleName
val keyPrefix = "selected_repo_for_id"

fun getSelectedRepoPath(id: Int) : String = context.applicationContext
.getSharedPreferences("SETTINGS", Context.MODE_PRIVATE)
.getString("selected_repo_for_id${id}", ALL_ISSUES_TEXT)!!
.getString("${keyPrefix}${id}", ALL_ISSUES_TEXT)!!

fun setSelectedRepoPath(id: Int, repoPath: String) {
context.applicationContext
.getSharedPreferences("SETTINGS", Context.MODE_PRIVATE)
.edit()
.putString("selected_repo_for_id${id}", repoPath)
.putString("${keyPrefix}${id}", repoPath)
.apply()
Log.d(TAG, "[save] selected_repo_for_id${id} : ${repoPath}")
Log.d(TAG, "[save] ${keyPrefix}${id} : ${repoPath}")
}

fun removeSelectedRepoPath(id: Int) {
context.applicationContext
.getSharedPreferences("SETTINGS", Context.MODE_PRIVATE)
.edit()
.remove("${keyPrefix}${id}")
.apply()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tistory.umbum.github_issue_widget_app.ui.reposelect
package com.tistory.umbum.github_issue_widget_app.ui

import android.databinding.BindingAdapter
import android.support.v7.widget.RecyclerView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ package com.tistory.umbum.github_issue_widget_app.ui.login
import android.appwidget.AppWidgetManager
import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.widget.Toast
import com.tistory.umbum.github_issue_widget_app.CLIENT_ID
import com.tistory.umbum.github_issue_widget_app.DBG_TAG
import com.tistory.umbum.github_issue_widget_app.REDIRECT_URI
import com.tistory.umbum.github_issue_widget_app.ui.widget.IssueWidget
import com.tistory.umbum.github_issue_widget_app.util.openCustomTab
import android.content.ComponentName
import android.content.Context


/**
Expand All @@ -24,6 +23,8 @@ import android.content.Context
* 그냥 OAuthLoginActivity onCreate하자 마자 CCT로 OAuth 로그인하도록 넘어가게 구성했다.
*/
class OAuthLoginActivity : AppCompatActivity() {
val TAG = this::class.java.simpleName

private val viewModel: OAuthLoginViewModel by lazy {
ViewModelProviders
.of(this, OAuthLoginViewModelFactory(this.application))
Expand Down Expand Up @@ -51,7 +52,7 @@ class OAuthLoginActivity : AppCompatActivity() {
override fun onResume() {
super.onResume()
val intent = getIntent()
Log.d(DBG_TAG, "OAuthLoginActivity.onResume: intent is ${intent?.action}")
Log.d(TAG, "OAuthLoginActivity.onResume: intent is ${intent?.action}")
}

/**
Expand Down Expand Up @@ -81,10 +82,10 @@ class OAuthLoginActivity : AppCompatActivity() {
finish()
})
} else {
Log.d(DBG_TAG, "OAuthLoginActivity.onNewIntent: intent.data or getQueryParameter('code') is null")
Log.d(TAG, "OAuthLoginActivity.onNewIntent: intent.data or getQueryParameter('code') is null")
}
} else {
Log.d(DBG_TAG, "OAuthLoginActivity.onNewIntent: intent is ${intent?.action}")
Log.d(TAG, "OAuthLoginActivity.onNewIntent: intent is ${intent?.action}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager
import android.util.Log
import com.tistory.umbum.github_issue_widget_app.DBG_TAG
import com.tistory.umbum.github_issue_widget_app.R
import com.tistory.umbum.github_issue_widget_app.databinding.ActivityRepoSelectBinding

class RepoSelectActivity : AppCompatActivity() {
val TAG = this::class.java.simpleName

private val viewModel: RepoSelectViewModel by lazy {
ViewModelProviders
Expand All @@ -26,7 +26,7 @@ class RepoSelectActivity : AppCompatActivity() {

val appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
Log.d(DBG_TAG, "RepoSelectActivity: appWidgetId is INVALID")
Log.d(TAG, "RepoSelectActivity: appWidgetId is INVALID")
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import android.arch.lifecycle.AndroidViewModel
import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProvider
import android.databinding.ObservableArrayList
import android.databinding.ObservableField
import android.util.Log
import android.widget.Toast
import com.tistory.umbum.github_issue_widget_app.ALL_ISSUES_ID
import com.tistory.umbum.github_issue_widget_app.ALL_ISSUES_TEXT
import com.tistory.umbum.github_issue_widget_app.data.remote.api.GithubApiClient
import com.tistory.umbum.github_issue_widget_app.data.model.RepoItem
import com.tistory.umbum.github_issue_widget_app.data.local.preferences.AccessTokenRepository
import com.tistory.umbum.github_issue_widget_app.data.model.RepoItem
import com.tistory.umbum.github_issue_widget_app.data.remote.api.GithubApiClient
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -20,6 +21,7 @@ class RepoSelectViewModel(app: Application) : AndroidViewModel(app) {
private val TAG = this::class.java.simpleName
private val accessTokenRepository = AccessTokenRepository(getApplication())
val repoItems = ObservableArrayList<RepoItem>()
val requestProgress = ObservableField<Boolean>()

init {
requestRepos()
Expand All @@ -30,6 +32,8 @@ class RepoSelectViewModel(app: Application) : AndroidViewModel(app) {
}

fun requestRepos() {
repoItems.clear()
requestProgress.set(true)
val access_token = accessTokenRepository.accessToken
if (access_token == null) {
Log.d(TAG, "RepoSelectViewModel.requestRepos: accessToken is null")
Expand All @@ -41,19 +45,20 @@ class RepoSelectViewModel(app: Application) : AndroidViewModel(app) {

GithubApiClient.client.getMyRepos(token_string).enqueue(object : Callback<List<RepoItem>> {
override fun onFailure(call: Call<List<RepoItem>>, t: Throwable) {
Log.e(TAG, "onFailure: repoistory request fail", t)
requestProgress.set(false)
Log.e(TAG, "onFailure: github repository request fail", t)
Toast.makeText(getApplication(), "Request for repository information failed.", Toast.LENGTH_LONG).show()
}

override fun onResponse(call: Call<List<RepoItem>>, response: Response<List<RepoItem>>) {
requestProgress.set(false)
val repos = response.body()?.toMutableList()
if (repos != null) {
repos.add(0, allIssues)
repoItems.clear()
repoItems.add(allIssues)
repoItems.addAll(repos)
} else {
Log.e(TAG, "onResponse: response.body() is null.")
Toast.makeText(getApplication(), "Failed to get repository information.π", Toast.LENGTH_LONG).show()
Toast.makeText(getApplication(), "Failed to get repository information.", Toast.LENGTH_LONG).show()
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,14 @@ class IssueListFactory(val context: Context, val intent: Intent): RemoteViewsSer

override fun getCount(): Int {
// 0..getCount()만큼 getViewAt()이 호출된다.
Log.d(TAG, "IssueListFactory.getCount: return ${issueItems.size}")
return issueItems.size
}

override fun getViewTypeCount(): Int {
// issue_item의 layout으로 2종류를 사용하니까, getViewTypeCount는 2를 리턴해야 한다.
return 2
return 2 // issue_item의 layout으로 2종류를 사용하고 있다.
}

override fun onDestroy() {
// In onDestroy() you should tear down anything that was setup for your data source,
// eg. cursors, connections, etc.
userSelectedRepository.removeSelectedRepoPath(appWidgetId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.net.Uri
import android.util.Log
import android.widget.RemoteViews
import com.tistory.umbum.github_issue_widget_app.DBG_TAG
import com.tistory.umbum.github_issue_widget_app.ui.config.ConfigActivity
import com.tistory.umbum.github_issue_widget_app.R
import com.tistory.umbum.github_issue_widget_app.data.local.preferences.UserSelectedRepository
import com.tistory.umbum.github_issue_widget_app.util.openCustomTab
import com.tistory.umbum.github_issue_widget_app.ui.config.ConfigActivity
import com.tistory.umbum.github_issue_widget_app.ui.reposelect.RepoSelectActivity
import com.tistory.umbum.github_issue_widget_app.util.openCustomTab


const val ACTION_UPDATE = "android.appwidget.action.APPWIDGET_UPDATE"
Expand All @@ -22,6 +22,7 @@ const val ACTION_CLICK = "android.appwidget.action.ISSUE_CLICK"
* IssueWidgetProvider
*/
class IssueWidget : AppWidgetProvider() {
val TAG = this::class.java.simpleName

override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
// There may be multiple widgets active, so update all of them
Expand All @@ -42,26 +43,27 @@ class IssueWidget : AppWidgetProvider() {
super.onReceive(context, intent)
when (intent.action) {
ACTION_UPDATE -> {
val appWidgetId = intent.extras?.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) ?: AppWidgetManager.INVALID_APPWIDGET_ID
val appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
val appWidgetManager = AppWidgetManager.getInstance(context)
updateAppWidget(context, appWidgetManager, appWidgetId)
}
else {
Log.d(DBG_TAG, "onReceive(broadcast receive) : appWidgetId is null")
Log.d(TAG, "onReceive(broadcast receive) : INVALID_APPWIDGET_ID")
}
}
ACTION_CLICK -> {
val url = intent.extras?.getString("url")
url?.let { openCustomTab(context, url) } ?: Log.d(DBG_TAG, "[onReceive] url is null")
url?.let { openCustomTab(context, url, FLAG_ACTIVITY_NEW_TASK) } ?: Log.d(TAG, "[onReceive] url is null")
}
else -> {
Log.d(DBG_TAG, "[onReceive] action = ${intent.action}")
Log.d(TAG, "[onReceive] action = ${intent.action}")
}
}
}

companion object {
val TAG = this::class.java.enclosingClass.simpleName + "\$companion"

internal fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager,
appWidgetId: Int) {
Expand All @@ -71,17 +73,17 @@ class IssueWidget : AppWidgetProvider() {
appWidgetManager를 통해 런쳐 어플리케이션에 전달하면, 런쳐 어플리케이션이 이 뷰를 그리는 방식으로 동작한다.
*/
val views = RemoteViews(context.packageName, R.layout.issue_widget)
Log.d(DBG_TAG, "IssueWidget.onUpdate: id ${appWidgetId}")
Log.d(TAG, "IssueWidget.onUpdate: id ${appWidgetId}")

val userSelectedRepository = UserSelectedRepository(context)
val repoPath = userSelectedRepository.getSelectedRepoPath(appWidgetId)
views.setTextViewText(R.id.repo_select_btn, repoPath)
Log.d(DBG_TAG, "[set repo btn text] ${repoPath}")
Log.d(TAG, "[set repo btn text] ${repoPath}")

// repo select button
val repoSelectIntent = Intent(context, RepoSelectActivity::class.java)
repoSelectIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) // 위젯 마다 다른 repo를 선택할 수 있어야 하므로. 어떤 위젯에서 레포 선택을 호출했는지 정보 필요.
val repoSelectPendingIntent = PendingIntent.getActivity(context, 0, repoSelectIntent, PendingIntent.FLAG_UPDATE_CURRENT)
val repoSelectPendingIntent = PendingIntent.getActivity(context, appWidgetId, repoSelectIntent, PendingIntent.FLAG_UPDATE_CURRENT)
views.setOnClickPendingIntent(R.id.repo_select_btn, repoSelectPendingIntent)

// update button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import android.net.Uri
import android.support.customtabs.CustomTabsIntent


fun openCustomTab(context: Context, uri: Uri) {
fun openCustomTab(context: Context, uri: Uri, flags: Int? = null) {
val builder = CustomTabsIntent.Builder()
val customTabsIntent = builder.build()
if (flags != null) {
customTabsIntent.intent.setFlags(flags)
}
customTabsIntent.launchUrl(context, uri)
}

fun openCustomTab(context: Context, url: String) {
openCustomTab(context, Uri.parse(url))
fun openCustomTab(context: Context, url: String, flags: Int? = null) {
openCustomTab(context, Uri.parse(url), flags)
}
Loading

0 comments on commit 8ac8d1e

Please sign in to comment.