2020-03-05 19:02:22 +01:00
|
|
|
package com.h.pixeldroid
|
|
|
|
|
2020-03-05 22:46:40 +01:00
|
|
|
import android.content.ActivityNotFoundException
|
|
|
|
import android.content.Context
|
2020-03-06 18:24:20 +01:00
|
|
|
import android.content.Intent
|
2020-03-05 22:46:40 +01:00
|
|
|
import android.content.SharedPreferences
|
2020-03-05 20:36:23 +01:00
|
|
|
import android.net.Uri
|
2020-03-05 19:02:22 +01:00
|
|
|
import android.os.Bundle
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
import android.util.Log
|
2020-04-01 19:38:21 +02:00
|
|
|
import android.view.View
|
2020-05-14 20:14:41 +02:00
|
|
|
import android.widget.ArrayAdapter
|
|
|
|
import android.widget.Toast
|
2020-03-05 20:36:23 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2020-03-05 22:46:40 +01:00
|
|
|
import androidx.browser.customtabs.CustomTabsIntent
|
2020-03-05 20:36:23 +01:00
|
|
|
import com.h.pixeldroid.api.PixelfedAPI
|
2020-05-14 20:14:41 +02:00
|
|
|
import com.h.pixeldroid.db.AppDatabase
|
|
|
|
import com.h.pixeldroid.db.InstanceDatabaseEntity
|
|
|
|
import com.h.pixeldroid.objects.Account
|
2020-03-06 08:37:59 +01:00
|
|
|
import com.h.pixeldroid.objects.Application
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
import com.h.pixeldroid.objects.Instance
|
2020-03-06 18:24:20 +01:00
|
|
|
import com.h.pixeldroid.objects.Token
|
2020-05-14 20:14:41 +02:00
|
|
|
import com.h.pixeldroid.utils.DBUtils
|
|
|
|
import com.h.pixeldroid.utils.Utils
|
|
|
|
import kotlinx.android.synthetic.main.activity_login.connect_instance_button
|
|
|
|
import kotlinx.android.synthetic.main.activity_login.editText
|
|
|
|
import kotlinx.android.synthetic.main.activity_login.login_activity_connection_required_text
|
|
|
|
import kotlinx.android.synthetic.main.activity_login.login_activity_instance_chooser
|
|
|
|
import kotlinx.android.synthetic.main.activity_login.login_activity_instance_chooser_button
|
|
|
|
import kotlinx.android.synthetic.main.activity_login.login_activity_instance_chooser_layout
|
|
|
|
import kotlinx.android.synthetic.main.activity_login.login_activity_instance_chooser_offline_text
|
|
|
|
import kotlinx.android.synthetic.main.activity_login.login_activity_instance_input_layout
|
|
|
|
import kotlinx.android.synthetic.main.activity_login.progressLayout
|
|
|
|
import kotlinx.android.synthetic.main.activity_login.whatsAnInstanceTextView
|
|
|
|
import okhttp3.internal.toImmutableList
|
2020-03-05 22:46:40 +01:00
|
|
|
import retrofit2.Call
|
|
|
|
import retrofit2.Callback
|
|
|
|
import retrofit2.Response
|
2020-03-05 19:02:22 +01:00
|
|
|
|
2020-04-10 16:12:03 +02:00
|
|
|
|
2020-03-06 08:49:26 +01:00
|
|
|
class LoginActivity : AppCompatActivity() {
|
2020-03-05 22:46:40 +01:00
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
companion object {
|
|
|
|
private const val TAG = "Login Activity"
|
|
|
|
private const val PACKAGE_ID = BuildConfig.APPLICATION_ID
|
|
|
|
private const val SCOPE = "read write follow"
|
|
|
|
}
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
private lateinit var oauthScheme: String
|
|
|
|
private lateinit var appName: String
|
2020-03-05 22:46:40 +01:00
|
|
|
private lateinit var preferences: SharedPreferences
|
2020-05-14 20:14:41 +02:00
|
|
|
private lateinit var db: AppDatabase
|
|
|
|
private lateinit var pixelfedAPI: PixelfedAPI
|
|
|
|
private var inputVisibility: Int = View.GONE
|
|
|
|
private var chooserVisibility: Int = View.GONE
|
2020-03-05 19:02:22 +01:00
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.activity_login)
|
2020-03-05 20:36:23 +01:00
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
loadingAnimation(true)
|
|
|
|
appName = getString(R.string.app_name)
|
|
|
|
oauthScheme = getString(R.string.auth_scheme)
|
|
|
|
preferences = getSharedPreferences("$PACKAGE_ID.pref", Context.MODE_PRIVATE)
|
|
|
|
db = DBUtils.initDB(applicationContext)
|
|
|
|
|
|
|
|
// check for stored accounts/instances
|
|
|
|
val accounts: List<Map<String, String>> = getSavedAccounts()
|
|
|
|
if (accounts.isNotEmpty()) {
|
|
|
|
displayChooser(accounts)
|
|
|
|
login_activity_instance_chooser_button.setOnClickListener {
|
|
|
|
val choice: Int = login_activity_instance_chooser.selectedItemId.toInt()
|
|
|
|
setPreferences(accounts[choice])
|
|
|
|
val intent = Intent(this, MainActivity::class.java)
|
|
|
|
startActivity(intent)
|
|
|
|
}
|
|
|
|
}
|
2020-04-16 12:46:40 +02:00
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
if (Utils.hasInternet(applicationContext)) {
|
|
|
|
connect_instance_button.setOnClickListener {
|
|
|
|
registerAppToServer(normalizeDomain(editText.text.toString()))
|
|
|
|
}
|
|
|
|
whatsAnInstanceTextView.setOnClickListener{ whatsAnInstance() }
|
|
|
|
inputVisibility = View.VISIBLE
|
|
|
|
} else {
|
|
|
|
if (accounts.isEmpty()) {
|
|
|
|
login_activity_connection_required_text.visibility = View.VISIBLE
|
|
|
|
} else {
|
|
|
|
login_activity_instance_chooser_offline_text.visibility = View.VISIBLE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loadingAnimation(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun getSavedAccounts(): List<Map<String, String>> {
|
|
|
|
val result = mutableListOf<Map<String, String>>()
|
|
|
|
val instances = db.instanceDao().getAll()
|
|
|
|
for (user in db.userDao().getAll()) {
|
|
|
|
val instance = instances.first {instance ->
|
|
|
|
instance.uri == user.instance_uri
|
|
|
|
}
|
|
|
|
result.add(mapOf(
|
|
|
|
Pair("username", user.username),
|
|
|
|
Pair("instance_title", instance.title),
|
|
|
|
Pair("instance_uri", instance.uri),
|
|
|
|
Pair("id", user.user_id)
|
|
|
|
))
|
|
|
|
}
|
|
|
|
return result.toImmutableList()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun displayChooser(accounts: List<Map<String, String>>) {
|
|
|
|
ArrayAdapter(
|
|
|
|
this,
|
|
|
|
android.R.layout.simple_spinner_item,
|
|
|
|
accounts.map { account ->
|
|
|
|
"${account["username"]}@${account["instance_title"]}"
|
|
|
|
}).also {
|
|
|
|
adapter ->
|
|
|
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
|
|
|
login_activity_instance_chooser.adapter = adapter
|
|
|
|
}
|
|
|
|
chooserVisibility = View.VISIBLE
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setPreferences(account: Map<String, String>) {
|
|
|
|
if (Utils.hasInternet(applicationContext))
|
|
|
|
registerAppToServer(normalizeDomain(account["instance_uri"].orEmpty()))
|
|
|
|
else
|
|
|
|
preferences.edit()
|
|
|
|
.putString("user_id", account["id"])
|
|
|
|
.apply()
|
2020-03-06 18:24:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onStart(){
|
|
|
|
super.onStart()
|
2020-05-14 20:14:41 +02:00
|
|
|
val url: Uri? = intent.data
|
2020-03-06 18:24:20 +01:00
|
|
|
|
2020-04-01 19:38:21 +02:00
|
|
|
//Check if the activity was started after the authentication
|
2020-05-14 20:14:41 +02:00
|
|
|
if (url == null || !url.toString().startsWith("$oauthScheme://$PACKAGE_ID")) return
|
2020-04-01 19:38:21 +02:00
|
|
|
loadingAnimation(true)
|
|
|
|
|
2020-03-07 18:13:26 +01:00
|
|
|
val code = url.getQueryParameter("code")
|
|
|
|
authenticate(code)
|
2020-03-06 18:24:20 +01:00
|
|
|
}
|
|
|
|
|
2020-04-01 19:38:21 +02:00
|
|
|
override fun onStop() {
|
|
|
|
super.onStop()
|
|
|
|
loadingAnimation(false)
|
|
|
|
}
|
|
|
|
|
2020-03-13 11:48:45 +01:00
|
|
|
override fun onBackPressed() {
|
|
|
|
}
|
|
|
|
|
2020-04-16 12:46:40 +02:00
|
|
|
private fun whatsAnInstance() {
|
|
|
|
val i = Intent(Intent.ACTION_VIEW)
|
|
|
|
i.data = Uri.parse("https://pixelfed.org/join")
|
|
|
|
startActivity(i)
|
|
|
|
}
|
|
|
|
|
2020-03-07 18:13:26 +01:00
|
|
|
private fun normalizeDomain(domain: String): String {
|
2020-05-14 20:14:41 +02:00
|
|
|
return "https://" + domain
|
|
|
|
.replace("http://", "")
|
|
|
|
.replace("https://", "")
|
|
|
|
.trim(Char::isWhitespace)
|
2020-03-07 18:13:26 +01:00
|
|
|
}
|
2020-03-05 22:46:40 +01:00
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
|
2020-03-07 18:13:26 +01:00
|
|
|
private fun registerAppToServer(normalizedDomain: String) {
|
2020-05-14 20:14:41 +02:00
|
|
|
loadingAnimation(true)
|
|
|
|
if (normalizedDomain.replace("https://", "").isNullOrBlank())
|
|
|
|
return failedRegistration(getString(R.string.login_empty_string_error))
|
|
|
|
PixelfedAPI.create(normalizedDomain).registerApplication(
|
|
|
|
appName,"$oauthScheme://$PACKAGE_ID", SCOPE
|
|
|
|
).enqueue(object : Callback<Application> {
|
2020-03-05 22:46:40 +01:00
|
|
|
override fun onResponse(call: Call<Application>, response: Response<Application>) {
|
|
|
|
if (!response.isSuccessful) {
|
2020-03-07 18:31:58 +01:00
|
|
|
return failedRegistration()
|
2020-03-05 22:46:40 +01:00
|
|
|
}
|
2020-05-14 20:14:41 +02:00
|
|
|
preferences.edit()
|
|
|
|
.putString("domain", normalizedDomain)
|
|
|
|
.apply()
|
|
|
|
val credentials = response.body() as Application
|
|
|
|
val clientId = credentials.client_id ?: return failedRegistration()
|
2020-03-06 18:24:20 +01:00
|
|
|
preferences.edit()
|
|
|
|
.putString("clientID", clientId)
|
2020-05-14 20:14:41 +02:00
|
|
|
.putString("clientSecret", credentials.client_secret)
|
2020-03-05 22:46:40 +01:00
|
|
|
.apply()
|
2020-03-07 18:13:26 +01:00
|
|
|
promptOAuth(normalizedDomain, clientId)
|
2020-03-05 22:46:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onFailure(call: Call<Application>, t: Throwable) {
|
2020-03-07 18:31:58 +01:00
|
|
|
return failedRegistration()
|
2020-03-05 22:46:40 +01:00
|
|
|
}
|
2020-05-14 20:14:41 +02:00
|
|
|
})
|
2020-03-06 18:24:20 +01:00
|
|
|
}
|
2020-03-05 20:36:23 +01:00
|
|
|
|
2020-03-07 18:13:26 +01:00
|
|
|
private fun promptOAuth(normalizedDomain: String, client_id: String) {
|
2020-03-06 18:24:20 +01:00
|
|
|
|
2020-03-13 11:48:45 +01:00
|
|
|
val url = "$normalizedDomain/oauth/authorize?" +
|
2020-03-05 22:46:40 +01:00
|
|
|
"client_id" + "=" + client_id + "&" +
|
2020-05-14 20:14:41 +02:00
|
|
|
"redirect_uri" + "=" + "$oauthScheme://$PACKAGE_ID" + "&" +
|
2020-03-05 22:46:40 +01:00
|
|
|
"response_type=code" + "&" +
|
2020-03-06 18:24:20 +01:00
|
|
|
"scope=$SCOPE"
|
2020-03-05 22:46:40 +01:00
|
|
|
|
|
|
|
val intent = CustomTabsIntent.Builder().build()
|
|
|
|
|
|
|
|
try {
|
2020-03-07 18:13:26 +01:00
|
|
|
intent.launchUrl(this, Uri.parse(url))
|
2020-03-05 22:46:40 +01:00
|
|
|
} catch (e: ActivityNotFoundException) {
|
2020-03-06 18:24:20 +01:00
|
|
|
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
|
|
|
if (browserIntent.resolveActivity(packageManager) != null) {
|
|
|
|
startActivity(browserIntent)
|
|
|
|
} else {
|
2020-03-07 18:31:58 +01:00
|
|
|
return failedRegistration(getString(R.string.browser_launch_failed))
|
2020-03-06 18:24:20 +01:00
|
|
|
}
|
2020-03-05 22:46:40 +01:00
|
|
|
}
|
2020-03-05 19:02:22 +01:00
|
|
|
}
|
2020-03-07 18:13:26 +01:00
|
|
|
|
|
|
|
private fun authenticate(code: String?) {
|
|
|
|
|
|
|
|
// Get previous values from preferences
|
2020-05-14 20:14:41 +02:00
|
|
|
val domain = preferences.getString("domain", "") as String
|
|
|
|
val clientId = preferences.getString("clientID", "") as String
|
|
|
|
val clientSecret = preferences.getString("clientSecret", "") as String
|
2020-03-07 18:13:26 +01:00
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
if (code.isNullOrBlank() || domain.isBlank() || clientId.isBlank() || clientSecret.isBlank()) {
|
2020-03-07 18:31:58 +01:00
|
|
|
return failedRegistration(getString(R.string.auth_failed))
|
2020-03-07 18:13:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Successful authorization
|
|
|
|
val callback = object : Callback<Token> {
|
|
|
|
override fun onResponse(call: Call<Token>, response: Response<Token>) {
|
|
|
|
if (!response.isSuccessful || response.body() == null) {
|
2020-03-07 18:31:58 +01:00
|
|
|
return failedRegistration(getString(R.string.token_error))
|
2020-03-07 18:13:26 +01:00
|
|
|
}
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
authenticationSuccessful(response.body()!!.access_token)
|
2020-03-07 18:13:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onFailure(call: Call<Token>, t: Throwable) {
|
2020-03-07 18:31:58 +01:00
|
|
|
return failedRegistration(getString(R.string.token_error))
|
2020-03-07 18:13:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
pixelfedAPI = PixelfedAPI.create(domain)
|
|
|
|
pixelfedAPI.obtainToken(
|
|
|
|
clientId, clientSecret, "$oauthScheme://$PACKAGE_ID", SCOPE, code,
|
2020-03-07 18:13:26 +01:00
|
|
|
"authorization_code"
|
|
|
|
).enqueue(callback)
|
|
|
|
}
|
|
|
|
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
private fun authenticationSuccessful(accessToken: String) {
|
2020-05-14 20:14:41 +02:00
|
|
|
saveUserAndInstance(accessToken)
|
2020-03-07 18:13:26 +01:00
|
|
|
preferences.edit().putString("accessToken", accessToken).apply()
|
|
|
|
val intent = Intent(this, MainActivity::class.java)
|
|
|
|
startActivity(intent)
|
|
|
|
}
|
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
private fun failedRegistration(message: String = getString(R.string.registration_failed)) {
|
2020-04-01 19:38:21 +02:00
|
|
|
loadingAnimation(false)
|
2020-03-07 18:13:26 +01:00
|
|
|
editText.error = message
|
|
|
|
}
|
|
|
|
|
2020-04-01 19:38:21 +02:00
|
|
|
private fun loadingAnimation(on: Boolean){
|
|
|
|
if(on) {
|
2020-05-14 20:14:41 +02:00
|
|
|
login_activity_instance_input_layout.visibility = View.GONE
|
|
|
|
login_activity_instance_chooser_layout.visibility = View.GONE
|
2020-04-01 19:38:21 +02:00
|
|
|
progressLayout.visibility = View.VISIBLE
|
|
|
|
}
|
|
|
|
else {
|
2020-05-14 20:14:41 +02:00
|
|
|
login_activity_instance_input_layout.visibility = inputVisibility
|
|
|
|
login_activity_instance_chooser_layout.visibility = chooserVisibility
|
2020-04-01 19:38:21 +02:00
|
|
|
progressLayout.visibility = View.GONE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
private fun saveUserAndInstance(accessToken: String) {
|
|
|
|
preferences.edit().putInt("max_toot_chars", Instance.DEFAULT_MAX_TOOT_CHARS).apply()
|
|
|
|
pixelfedAPI.instance().enqueue(object : Callback<Instance> {
|
|
|
|
override fun onFailure(call: Call<Instance>, t: Throwable) {
|
|
|
|
}
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
override fun onResponse(call: Call<Instance>, response: Response<Instance>) {
|
|
|
|
if (response.isSuccessful && response.body() != null) {
|
|
|
|
val instance = response.body() as Instance
|
|
|
|
storeInstance(instance)
|
|
|
|
storeUser(accessToken)
|
|
|
|
}
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
}
|
2020-05-14 20:14:41 +02:00
|
|
|
})
|
|
|
|
}
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
private fun storeInstance(instance: Instance) {
|
|
|
|
val maxTootChars = instance.max_toot_chars.toInt()
|
|
|
|
preferences.edit().putInt("max_toot_chars", maxTootChars).apply()
|
|
|
|
preferences.edit().putString("instance_uri", instance.uri).apply()
|
|
|
|
val dbInstance = InstanceDatabaseEntity(
|
|
|
|
uri = instance.uri,
|
|
|
|
title = instance.title,
|
|
|
|
max_toot_chars = maxTootChars,
|
|
|
|
thumbnail = instance.thumbnail
|
|
|
|
)
|
|
|
|
db.instanceDao().insertInstance(dbInstance)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun storeUser(accessToken: String) {
|
|
|
|
pixelfedAPI.verifyCredentials("Bearer $accessToken")
|
|
|
|
.enqueue(object : Callback<Account> {
|
|
|
|
override fun onResponse(call: Call<Account>, response: Response<Account>) {
|
|
|
|
if (response.body() != null && response.isSuccessful) {
|
|
|
|
val user = response.body() as Account
|
|
|
|
preferences.edit().putString("user_id", user.id).apply()
|
|
|
|
DBUtils.addUser(
|
|
|
|
db,
|
|
|
|
user,
|
|
|
|
preferences.getString("instance_uri", null).orEmpty()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
override fun onFailure(call: Call<Account>, t: Throwable) {
|
|
|
|
}
|
|
|
|
})
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
}
|
|
|
|
|
2020-03-05 19:02:22 +01:00
|
|
|
}
|