2020-02-28 17:08:54 +01:00
|
|
|
package com.h.pixeldroid
|
|
|
|
|
2020-03-13 11:48:45 +01:00
|
|
|
import android.content.Context
|
2020-03-06 08:49:26 +01:00
|
|
|
import android.content.Intent
|
2020-03-13 11:48:45 +01:00
|
|
|
import android.content.SharedPreferences
|
2020-02-28 17:08:54 +01:00
|
|
|
import android.os.Bundle
|
2020-05-01 11:26:18 +02:00
|
|
|
import android.util.Log
|
2020-03-05 21:07:10 +01:00
|
|
|
import android.view.MenuItem
|
2020-05-01 11:26:18 +02:00
|
|
|
import android.view.View
|
2020-03-05 21:07:10 +01:00
|
|
|
import androidx.annotation.NonNull
|
2020-03-08 12:54:18 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2020-03-05 21:07:10 +01:00
|
|
|
import androidx.core.view.GravityCompat
|
2020-03-12 22:23:25 +01:00
|
|
|
import androidx.fragment.app.Fragment
|
2020-03-13 11:48:45 +01:00
|
|
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
2020-03-05 21:07:10 +01:00
|
|
|
import com.google.android.material.navigation.NavigationView
|
2020-03-13 11:48:45 +01:00
|
|
|
import com.google.android.material.tabs.TabLayoutMediator
|
2020-05-01 11:26:18 +02: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.UserDatabaseEntity
|
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.fragments.NewPostFragment
|
2020-04-30 17:54:21 +02:00
|
|
|
import com.h.pixeldroid.fragments.SearchDiscoverFragment
|
|
|
|
import com.h.pixeldroid.fragments.feeds.PostsFeedFragment
|
2020-04-01 19:38:21 +02:00
|
|
|
import com.h.pixeldroid.fragments.feeds.NotificationsFragment
|
2020-05-14 20:14:41 +02:00
|
|
|
import com.h.pixeldroid.fragments.feeds.OfflineFeedFragment
|
2020-05-03 22:48:05 +02:00
|
|
|
import com.h.pixeldroid.fragments.feeds.PublicTimelineFragment
|
2020-05-01 11:26:18 +02:00
|
|
|
import com.h.pixeldroid.objects.Account
|
2020-05-14 20:14:41 +02:00
|
|
|
import com.h.pixeldroid.utils.DBUtils
|
2020-05-01 11:26:18 +02:00
|
|
|
import com.h.pixeldroid.utils.ImageConverter
|
2020-05-14 20:14:41 +02:00
|
|
|
import com.h.pixeldroid.utils.Utils.Companion.hasInternet
|
2020-05-01 11:26:18 +02:00
|
|
|
import retrofit2.Call
|
|
|
|
import retrofit2.Callback
|
|
|
|
import retrofit2.Response
|
2020-05-14 20:14:41 +02:00
|
|
|
import kotlinx.android.synthetic.main.activity_main.*
|
|
|
|
import kotlinx.android.synthetic.main.nav_header.view.drawer_account_name
|
|
|
|
import kotlinx.android.synthetic.main.nav_header.view.drawer_avatar
|
2020-03-13 12:17:17 +01:00
|
|
|
|
2020-03-05 21:07:10 +01:00
|
|
|
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
|
|
|
|
|
2020-03-13 11:48:45 +01:00
|
|
|
private lateinit var preferences: SharedPreferences
|
2020-04-30 17:54:21 +02:00
|
|
|
private val searchDiscoverFragment: SearchDiscoverFragment = SearchDiscoverFragment()
|
2020-05-14 20:14:41 +02:00
|
|
|
private lateinit var db: AppDatabase
|
2020-03-13 11:48:45 +01:00
|
|
|
|
2020-02-28 17:08:54 +01:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
2020-04-23 19:49:30 +02:00
|
|
|
setTheme(R.style.AppTheme_NoActionBar)
|
2020-02-28 17:08:54 +01:00
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.activity_main)
|
2020-03-05 21:07:10 +01:00
|
|
|
|
2020-03-13 11:48:45 +01:00
|
|
|
preferences = getSharedPreferences(
|
|
|
|
"${BuildConfig.APPLICATION_ID}.pref", Context.MODE_PRIVATE
|
|
|
|
)
|
2020-05-14 20:14:41 +02:00
|
|
|
db = DBUtils.initDB(applicationContext)
|
2020-03-12 22:23:25 +01:00
|
|
|
|
2020-03-13 11:48:45 +01:00
|
|
|
//Check if we have logged in and gotten an access token
|
2020-05-14 20:14:41 +02:00
|
|
|
if((hasInternet(applicationContext) && !preferences.contains("accessToken"))
|
|
|
|
|| (!hasInternet(applicationContext) && !preferences.contains("user_id"))) {
|
2020-03-13 11:48:45 +01:00
|
|
|
launchActivity(LoginActivity())
|
As a user I want to be able to see posts in a feed (#28)
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* rebased from master
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* rebased from master
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* fixed another merge problem
* trying my best to merge
* removed drawable definition in activity_post.xml
* implements swipe motion
add a new class to implement swipe motion
add the swipe right from home page to display settings
passed the homepage in a fragment
* transform profile activity into fragment
transformed profile activity and layout into fragment
linked it with a swipe motion
* Implement swipeable tabs
* Ask for login on first start, add API endpoints, change profile to show the user's profile
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* layout changes
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* rebase on other branch
* moved the feed to the home page
* Add tests
* delete test for now
* Adapt test to changes (no more profile from drawer)
* Add unit test for api
* Add test for profile, refactor to allow testing, add exception to security policy to allow tests
* Adapt test to new situation
* Fix typo due to change
* refactor somewhat
* added a feed test
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* refactoring
* refactoring
* removed wrong annotation in unit test
* WIP posts
* WIP posts
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* layout changes
* moved a test file
* refactoring
* refactoring
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* rebase on other branch
* moved the feed to the home page
* added a feed test
* added a working feed test
* fixed broken test
* merged with master
* added a max height for images and made profile pictures round
* Added a default image for the post
* created a PostActivity to look a single posts
* fixed buggy postActivity
* Complete overhall of the feed UI
* removed test that didn't please Travis
* removed legacy test
* changed feedAdapter init location (outside of network callback)
Co-authored-by: Matthieu <61561059+Wv5twkFEKh54vo4tta9yu7dHa3@users.noreply.github.com>
Co-authored-by: Ulysse Widmer <ulysse.widmer@epfl.ch>
2020-03-16 09:38:35 +01:00
|
|
|
} else {
|
2020-05-01 11:26:18 +02:00
|
|
|
setupDrawer()
|
2020-04-01 19:38:21 +02:00
|
|
|
val tabs = arrayOf(
|
2020-05-14 20:14:41 +02:00
|
|
|
if (hasInternet(applicationContext)) PostsFeedFragment()
|
|
|
|
else OfflineFeedFragment(),
|
2020-04-30 17:54:21 +02:00
|
|
|
searchDiscoverFragment,
|
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
|
|
|
NewPostFragment(),
|
2020-04-01 19:38:21 +02:00
|
|
|
NotificationsFragment(),
|
2020-05-03 22:48:05 +02:00
|
|
|
PublicTimelineFragment()
|
2020-04-10 12:55:02 +02:00
|
|
|
)
|
As a user I want to be able to see posts in a feed (#28)
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* rebased from master
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* rebased from master
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* fixed another merge problem
* trying my best to merge
* removed drawable definition in activity_post.xml
* implements swipe motion
add a new class to implement swipe motion
add the swipe right from home page to display settings
passed the homepage in a fragment
* transform profile activity into fragment
transformed profile activity and layout into fragment
linked it with a swipe motion
* Implement swipeable tabs
* Ask for login on first start, add API endpoints, change profile to show the user's profile
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* layout changes
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* rebase on other branch
* moved the feed to the home page
* Add tests
* delete test for now
* Adapt test to changes (no more profile from drawer)
* Add unit test for api
* Add test for profile, refactor to allow testing, add exception to security policy to allow tests
* Adapt test to new situation
* Fix typo due to change
* refactor somewhat
* added a feed test
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* refactoring
* refactoring
* removed wrong annotation in unit test
* WIP posts
* WIP posts
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* layout changes
* moved a test file
* refactoring
* refactoring
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* rebase on other branch
* moved the feed to the home page
* added a feed test
* added a working feed test
* fixed broken test
* merged with master
* added a max height for images and made profile pictures round
* Added a default image for the post
* created a PostActivity to look a single posts
* fixed buggy postActivity
* Complete overhall of the feed UI
* removed test that didn't please Travis
* removed legacy test
* changed feedAdapter init location (outside of network callback)
Co-authored-by: Matthieu <61561059+Wv5twkFEKh54vo4tta9yu7dHa3@users.noreply.github.com>
Co-authored-by: Ulysse Widmer <ulysse.widmer@epfl.ch>
2020-03-16 09:38:35 +01:00
|
|
|
setupTabs(tabs)
|
|
|
|
}
|
2020-05-01 11:26:18 +02:00
|
|
|
}
|
2020-04-30 20:01:35 +02:00
|
|
|
|
2020-05-01 11:26:18 +02:00
|
|
|
private fun setupDrawer() {
|
2020-05-14 20:14:41 +02:00
|
|
|
nav_view.setNavigationItemSelectedListener(this)
|
|
|
|
if (hasInternet(applicationContext)) {
|
|
|
|
val accessToken = preferences.getString("accessToken", "")
|
|
|
|
val pixelfedAPI = PixelfedAPI.create("${preferences.getString("domain", "")}")
|
|
|
|
pixelfedAPI.verifyCredentials("Bearer $accessToken")
|
|
|
|
.enqueue(object : Callback<Account> {
|
|
|
|
override fun onResponse(call: Call<Account>, response: Response<Account>) {
|
|
|
|
if (response.body() != null && response.isSuccessful) {
|
|
|
|
val account = response.body() as Account
|
|
|
|
DBUtils.addUser(db, account)
|
|
|
|
fillDrawerAccountInfo(account)
|
|
|
|
}
|
2020-05-01 11:26:18 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
override fun onFailure(call: Call<Account>, t: Throwable) {
|
|
|
|
Log.e("DRAWER ACCOUNT:", t.toString())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
val userId = preferences.getString("user_id", null).orEmpty()
|
|
|
|
if (userId.isNotEmpty()) {
|
|
|
|
val user: UserDatabaseEntity = db.userDao().getUserWithId(userId)
|
|
|
|
val account = Account(
|
|
|
|
id = user.user_id,
|
|
|
|
username = user.username,
|
|
|
|
display_name = user.display_name,
|
|
|
|
avatar_static = user.avatar_static
|
|
|
|
)
|
|
|
|
fillDrawerAccountInfo(account)
|
|
|
|
} else {
|
|
|
|
launchActivity(LoginActivity())
|
|
|
|
}
|
|
|
|
}
|
2020-03-12 22:23:25 +01:00
|
|
|
}
|
2020-03-04 18:04:55 +01:00
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
private fun fillDrawerAccountInfo(account: Account) {
|
|
|
|
val drawerAvatar = nav_view.getHeaderView(0).drawer_avatar
|
|
|
|
val drawerAccountName = nav_view.getHeaderView(0).drawer_account_name
|
|
|
|
ImageConverter.setRoundImageFromURL(
|
|
|
|
View(applicationContext),
|
|
|
|
account.avatar_static,
|
|
|
|
drawerAvatar
|
|
|
|
)
|
|
|
|
drawerAvatar.setOnClickListener { launchActivity(ProfileActivity()) }
|
|
|
|
// Set account name
|
|
|
|
drawerAccountName.apply {
|
|
|
|
text = account.display_name
|
|
|
|
setOnClickListener { launchActivity(ProfileActivity()) }
|
|
|
|
}
|
|
|
|
}
|
2020-05-01 11:26:18 +02:00
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
private fun setupTabs(tab_array: Array<Fragment>){
|
|
|
|
view_pager.adapter = object : FragmentStateAdapter(this) {
|
2020-03-13 11:48:45 +01:00
|
|
|
override fun createFragment(position: Int): Fragment {
|
2020-05-14 20:14:41 +02:00
|
|
|
return tab_array[position]
|
2020-03-13 11:48:45 +01:00
|
|
|
}
|
2020-03-12 22:23:25 +01:00
|
|
|
|
2020-03-13 11:48:45 +01:00
|
|
|
override fun getItemCount(): Int {
|
|
|
|
return 5
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 20:14:41 +02:00
|
|
|
TabLayoutMediator(tabs, view_pager) { tab, position ->
|
2020-03-13 11:48:45 +01:00
|
|
|
when(position){
|
|
|
|
0 -> tab.icon = getDrawable(R.drawable.ic_home_white_24dp)
|
|
|
|
1 -> tab.icon = getDrawable(R.drawable.ic_search_white_24dp)
|
|
|
|
2 -> tab.icon = getDrawable(R.drawable.ic_photo_camera_white_24dp)
|
2020-03-18 20:56:42 +01:00
|
|
|
3 -> tab.icon = getDrawable(R.drawable.ic_heart)
|
2020-05-03 22:48:05 +02:00
|
|
|
4 -> tab.icon = getDrawable(R.drawable.ic_filter_black_24dp)
|
2020-03-13 11:48:45 +01:00
|
|
|
}
|
|
|
|
}.attach()
|
2020-03-05 21:07:10 +01:00
|
|
|
}
|
|
|
|
|
2020-03-12 23:27:40 +01:00
|
|
|
/**
|
2020-03-05 21:48:25 +01:00
|
|
|
When clicking in the drawer menu, go to the corresponding activity
|
2020-03-05 21:07:10 +01:00
|
|
|
*/
|
|
|
|
override fun onNavigationItemSelected(@NonNull item: MenuItem): Boolean {
|
|
|
|
when (item.itemId){
|
2020-05-01 11:26:18 +02:00
|
|
|
R.id.nav_account -> launchActivity(ProfileActivity())
|
2020-03-08 12:54:18 +01:00
|
|
|
R.id.nav_settings -> launchActivity(SettingsActivity())
|
2020-04-17 15:07:04 +02:00
|
|
|
R.id.nav_logout -> launchActivity(LoginActivity())
|
2020-03-05 21:07:10 +01:00
|
|
|
}
|
|
|
|
|
2020-05-14 20:14:41 +02:00
|
|
|
drawer_layout.closeDrawer(GravityCompat.START)
|
2020-03-05 21:07:10 +01:00
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-03-12 23:27:40 +01:00
|
|
|
/**
|
2020-03-08 20:41:01 +01:00
|
|
|
Launches the given activity and put it as the current one
|
2020-03-05 22:49:16 +01:00
|
|
|
*/
|
2020-03-08 12:54:18 +01:00
|
|
|
private fun launchActivity(activity: AppCompatActivity) {
|
|
|
|
val intent = Intent(this, activity::class.java)
|
|
|
|
startActivity(intent)
|
2020-03-05 22:49:16 +01:00
|
|
|
}
|
|
|
|
|
2020-03-12 23:27:40 +01:00
|
|
|
/**
|
|
|
|
Closes the drawer if it is open, when we press the back button
|
2020-03-05 21:07:10 +01:00
|
|
|
*/
|
|
|
|
override fun onBackPressed() {
|
2020-05-14 20:14:41 +02:00
|
|
|
if(drawer_layout.isDrawerOpen(GravityCompat.START)){
|
|
|
|
drawer_layout.closeDrawer(GravityCompat.START)
|
2020-03-05 21:07:10 +01:00
|
|
|
} else {
|
|
|
|
super.onBackPressed()
|
|
|
|
}
|
2020-02-28 17:08:54 +01:00
|
|
|
}
|
2020-03-04 18:04:55 +01:00
|
|
|
|
As a user I want to be able to see posts in a feed (#28)
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* rebased from master
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* rebased from master
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* fixed another merge problem
* trying my best to merge
* removed drawable definition in activity_post.xml
* implements swipe motion
add a new class to implement swipe motion
add the swipe right from home page to display settings
passed the homepage in a fragment
* transform profile activity into fragment
transformed profile activity and layout into fragment
linked it with a swipe motion
* Implement swipeable tabs
* Ask for login on first start, add API endpoints, change profile to show the user's profile
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* layout changes
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* rebase on other branch
* moved the feed to the home page
* Add tests
* delete test for now
* Adapt test to changes (no more profile from drawer)
* Add unit test for api
* Add test for profile, refactor to allow testing, add exception to security policy to allow tests
* Adapt test to new situation
* Fix typo due to change
* refactor somewhat
* added a feed test
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* refactoring
* refactoring
* removed wrong annotation in unit test
* WIP posts
* WIP posts
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* layout changes
* moved a test file
* refactoring
* refactoring
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* rebase on other branch
* moved the feed to the home page
* added a feed test
* added a working feed test
* fixed broken test
* merged with master
* added a max height for images and made profile pictures round
* Added a default image for the post
* created a PostActivity to look a single posts
* fixed buggy postActivity
* Complete overhall of the feed UI
* removed test that didn't please Travis
* removed legacy test
* changed feedAdapter init location (outside of network callback)
Co-authored-by: Matthieu <61561059+Wv5twkFEKh54vo4tta9yu7dHa3@users.noreply.github.com>
Co-authored-by: Ulysse Widmer <ulysse.widmer@epfl.ch>
2020-03-16 09:38:35 +01:00
|
|
|
}
|