-
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.
* [Roles] We want the user to be able to click on each row and change the role of that user, and see that change reflected in the UI Bugs from most obvious to least: 1. We're showing the role UID, not the role String 3. The 2nd clause of the switch case in the UserAdapter::openRolePickerDialog is super broken (doesn't have break and is putting the wrong role_uid) 4. We're copy/pasting expensive getters 5. We're doing a lot of this role changing on the main thread 6. This dialog logic should probably live outside of the UserAdapter And probably more * Convert Java to Kotlin * Java -> Kotlin Co-authored-by: Amy Tang <[email protected]> Co-authored-by: Brian Amesbury <[email protected]>
- Loading branch information
1 parent
1a0f778
commit 962a8e5
Showing
29 changed files
with
311 additions
and
373 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
24 changes: 0 additions & 24 deletions
24
app/src/androidTest/java/buggy/plandroid/com/plandroidbugs/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
app/src/main/java/buggy/plandroid/com/plandroidbugs/MainActivity.java
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
app/src/main/java/buggy/plandroid/com/plandroidbugs/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,28 @@ | ||
package buggy.plandroid.com.plandroidbugs | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import buggy.plandroid.com.plandroidbugs.app.PlanDroidApp.Companion.getApp | ||
import io.reactivex.android.schedulers.AndroidSchedulers | ||
|
||
class MainActivity : AppCompatActivity() { | ||
@SuppressLint("CheckResult") | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
val userAdapter = UserAdapter() | ||
findViewById<RecyclerView>(R.id.recycler).apply { | ||
adapter = userAdapter | ||
layoutManager = LinearLayoutManager(this@MainActivity) | ||
} | ||
val userDao = getApp(applicationContext).database.userDao() | ||
|
||
// Listens to changes to the User database table. | ||
userDao.all().observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe { userAdapter.setUsers(it) } | ||
|
||
} | ||
} |
75 changes: 0 additions & 75 deletions
75
app/src/main/java/buggy/plandroid/com/plandroidbugs/PGApi.java
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
app/src/main/java/buggy/plandroid/com/plandroidbugs/PGApi.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,69 @@ | ||
package buggy.plandroid.com.plandroidbugs | ||
|
||
import android.util.Base64 | ||
import android.util.Log | ||
import com.fasterxml.jackson.annotation.JsonInclude | ||
import com.fasterxml.jackson.databind.DeserializationFeature | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
import io.reactivex.Observable | ||
import io.reactivex.android.schedulers.AndroidSchedulers | ||
import io.reactivex.schedulers.Schedulers | ||
import okhttp3.Interceptor | ||
import okhttp3.OkHttpClient | ||
import retrofit2.Retrofit | ||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory | ||
import retrofit2.converter.jackson.JacksonConverterFactory | ||
|
||
class PGApi { | ||
private val objectMapper = getObjectMapper() | ||
private val okHttpClient: OkHttpClient = OkHttpClient.Builder() | ||
.addInterceptor(provideUrlAndHeaderInterceptor()) | ||
.build() | ||
|
||
private fun provideUrlAndHeaderInterceptor(): Interceptor { | ||
return Interceptor { chain: Interceptor.Chain -> | ||
chain.proceed( | ||
chain.request().newBuilder() | ||
.addHeader("Accept", "application/vnd.plangrid+json; version=1") | ||
.addHeader("Authorization", basicAuth(AUTH_KEY + ":\"\"")) | ||
.build() | ||
) | ||
} | ||
} | ||
|
||
private val retrofit = Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(okHttpClient) | ||
.addConverterFactory(JacksonConverterFactory.create(ObjectMapper())) | ||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
.build() | ||
private val apiService = retrofit.create(PGApiService::class.java) | ||
|
||
val projectUsersObservable: Observable<UserList> = | ||
apiService.getAllUsers().subscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
|
||
companion object { | ||
const val BASE_URL = "https://plangrid-c-api-dispatcher-test.planfront.net" | ||
private const val AUTH_KEY = "521dd37f15b497e01fd7aeacab0892ec" | ||
|
||
fun basicAuth(toEncode: String): String { | ||
return String.format( | ||
"Basic %s", | ||
String(Base64.encode(toEncode.toByteArray(), Base64.DEFAULT)) | ||
).trim { it <= ' ' } | ||
} | ||
|
||
fun getObjectMapper(): ObjectMapper { | ||
val mapper = ObjectMapper() | ||
mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false) | ||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
mapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, false) | ||
mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false) | ||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) | ||
mapper.registerModule(KotlinModule()) | ||
return mapper | ||
} | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
app/src/main/java/buggy/plandroid/com/plandroidbugs/PGApiService.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
app/src/main/java/buggy/plandroid/com/plandroidbugs/PGApiService.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,13 @@ | ||
package buggy.plandroid.com.plandroidbugs | ||
|
||
import retrofit2.http.GET | ||
import io.reactivex.Observable | ||
import retrofit2.Call | ||
|
||
interface PGApiService { | ||
@GET("projects/fc6facf8-c69c-4780-bac1-1774bd91cc8c/users") | ||
fun getAllUsers(): Observable<UserList> | ||
|
||
@GET("projects/fc6facf8-c69c-4780-bac1-1774bd91cc8c/users/540e0bdcde37b40013533497") | ||
fun getUser(): Call<UserWire> | ||
} |
42 changes: 0 additions & 42 deletions
42
app/src/main/java/buggy/plandroid/com/plandroidbugs/UserAdapter.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.