2021-04-22 11:47:18 +02:00
|
|
|
package org.pixeldroid.app
|
2020-02-28 17:08:54 +01:00
|
|
|
|
2022-11-03 15:16:27 +01:00
|
|
|
import android.Manifest
|
2020-03-13 11:48:45 +01:00
|
|
|
import android.content.Context
|
2020-03-06 08:49:26 +01:00
|
|
|
import android.content.Intent
|
2022-11-03 15:16:27 +01:00
|
|
|
import android.content.pm.PackageManager
|
2020-05-19 09:49:34 +02:00
|
|
|
import android.graphics.drawable.Drawable
|
|
|
|
import android.net.Uri
|
2022-11-03 15:16:27 +01:00
|
|
|
import android.os.Build
|
2020-02-28 17:08:54 +01:00
|
|
|
import android.os.Bundle
|
2020-05-01 11:26:18 +02:00
|
|
|
import android.util.Log
|
2022-07-08 23:20:44 +02:00
|
|
|
import android.view.MenuItem
|
2020-05-01 11:26:18 +02:00
|
|
|
import android.view.View
|
2020-05-19 09:49:34 +02:00
|
|
|
import android.widget.ImageView
|
2022-11-03 15:16:27 +01:00
|
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
2020-03-08 12:54:18 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2022-11-03 15:16:27 +01:00
|
|
|
import androidx.core.app.ActivityCompat
|
2020-11-27 17:02:52 +01:00
|
|
|
import androidx.core.content.ContextCompat
|
2022-10-15 14:20:41 +02:00
|
|
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
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
|
2022-08-03 22:28:20 +02:00
|
|
|
import androidx.lifecycle.Lifecycle
|
2020-12-29 19:34:48 +01:00
|
|
|
import androidx.lifecycle.lifecycleScope
|
2022-08-03 22:28:20 +02:00
|
|
|
import androidx.lifecycle.repeatOnLifecycle
|
2020-11-27 17:02:52 +01:00
|
|
|
import androidx.paging.ExperimentalPagingApi
|
2021-05-09 23:49:11 +02:00
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2020-03-13 11:48:45 +01:00
|
|
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
2021-05-09 23:49:11 +02:00
|
|
|
import androidx.viewpager2.widget.ViewPager2
|
2022-07-10 13:42:19 +02:00
|
|
|
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
2020-05-19 09:49:34 +02:00
|
|
|
import com.bumptech.glide.Glide
|
2022-07-08 23:20:44 +02:00
|
|
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
2022-10-15 14:20:41 +02:00
|
|
|
import com.google.android.material.color.DynamicColors
|
2021-05-18 12:06:38 +02:00
|
|
|
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
|
|
|
|
import com.mikepenz.materialdrawer.iconics.iconicsIcon
|
|
|
|
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem
|
|
|
|
import com.mikepenz.materialdrawer.model.ProfileDrawerItem
|
|
|
|
import com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem
|
|
|
|
import com.mikepenz.materialdrawer.model.interfaces.*
|
|
|
|
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
|
|
|
|
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
|
|
|
import com.mikepenz.materialdrawer.widget.AccountHeaderView
|
2022-08-03 22:28:20 +02:00
|
|
|
import kotlinx.coroutines.launch
|
2021-05-18 12:06:38 +02:00
|
|
|
import org.ligi.tracedroid.sending.sendTraceDroidStackTracesIfExist
|
2021-04-22 11:47:18 +02:00
|
|
|
import org.pixeldroid.app.databinding.ActivityMainBinding
|
|
|
|
import org.pixeldroid.app.postCreation.camera.CameraFragment
|
2021-05-18 12:06:38 +02:00
|
|
|
import org.pixeldroid.app.posts.NestedScrollableHost
|
|
|
|
import org.pixeldroid.app.posts.feeds.cachedFeeds.CachedFeedFragment
|
2021-04-22 11:47:18 +02:00
|
|
|
import org.pixeldroid.app.posts.feeds.cachedFeeds.notifications.NotificationsFragment
|
|
|
|
import org.pixeldroid.app.posts.feeds.cachedFeeds.postFeeds.PostFeedFragment
|
|
|
|
import org.pixeldroid.app.profile.ProfileActivity
|
|
|
|
import org.pixeldroid.app.searchDiscover.SearchDiscoverFragment
|
|
|
|
import org.pixeldroid.app.settings.SettingsActivity
|
2023-10-29 17:48:27 +01:00
|
|
|
import org.pixeldroid.app.utils.BaseActivity
|
2022-08-03 22:28:20 +02:00
|
|
|
import org.pixeldroid.app.utils.api.objects.Notification
|
2021-04-22 11:47:18 +02:00
|
|
|
import org.pixeldroid.app.utils.db.addUser
|
|
|
|
import org.pixeldroid.app.utils.db.entities.HomeStatusDatabaseEntity
|
|
|
|
import org.pixeldroid.app.utils.db.entities.PublicFeedStatusDatabaseEntity
|
|
|
|
import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity
|
|
|
|
import org.pixeldroid.app.utils.hasInternet
|
2021-09-25 13:52:18 +02:00
|
|
|
import org.pixeldroid.app.utils.notificationsWorker.NotificationsWorker.Companion.INSTANCE_NOTIFICATION_TAG
|
|
|
|
import org.pixeldroid.app.utils.notificationsWorker.NotificationsWorker.Companion.SHOW_NOTIFICATION_TAG
|
|
|
|
import org.pixeldroid.app.utils.notificationsWorker.NotificationsWorker.Companion.USER_NOTIFICATION_TAG
|
2022-07-08 23:20:44 +02:00
|
|
|
import org.pixeldroid.app.utils.notificationsWorker.enablePullNotifications
|
2021-09-25 13:52:18 +02:00
|
|
|
import org.pixeldroid.app.utils.notificationsWorker.removeNotificationChannelsFromAccount
|
2022-10-23 22:58:41 +02:00
|
|
|
import java.time.Instant
|
2020-03-13 12:17:17 +01:00
|
|
|
|
2021-05-18 12:06:38 +02:00
|
|
|
|
2023-10-29 17:48:27 +01:00
|
|
|
class MainActivity : BaseActivity() {
|
2020-03-05 21:07:10 +01:00
|
|
|
|
2020-05-19 09:49:34 +02:00
|
|
|
private lateinit var header: AccountHeaderView
|
|
|
|
private var user: UserDatabaseEntity? = null
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
const val ADD_ACCOUNT_IDENTIFIER: Long = -13
|
|
|
|
}
|
2020-03-13 11:48:45 +01:00
|
|
|
|
2021-01-13 01:28:08 +01:00
|
|
|
private lateinit var binding: ActivityMainBinding
|
|
|
|
|
2021-11-26 16:54:29 +01:00
|
|
|
@OptIn(ExperimentalPagingApi::class)
|
2020-02-28 17:08:54 +01:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
2023-06-14 16:45:10 +02:00
|
|
|
installSplashScreen().setOnExitAnimationListener {
|
|
|
|
it.remove()
|
|
|
|
}
|
2022-10-15 14:20:41 +02:00
|
|
|
|
|
|
|
// Workaround for dynamic colors not applying due to splash screen?
|
|
|
|
DynamicColors.applyToActivityIfAvailable(this)
|
|
|
|
|
2020-02-28 17:08:54 +01:00
|
|
|
super.onCreate(savedInstanceState)
|
2021-01-13 01:28:08 +01:00
|
|
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
|
|
|
setContentView(binding.root)
|
2020-03-05 21:07:10 +01:00
|
|
|
|
2020-05-19 09:49:34 +02:00
|
|
|
//get the currently active user
|
|
|
|
user = db.userDao().getActiveUser()
|
|
|
|
|
2021-09-25 13:52:18 +02:00
|
|
|
if (notificationFromOtherUser()) return
|
|
|
|
|
2020-03-13 11:48:45 +01:00
|
|
|
//Check if we have logged in and gotten an access token
|
2020-05-19 09:49:34 +02:00
|
|
|
if (user == null) {
|
2021-02-05 14:48:12 +01:00
|
|
|
finish()
|
2021-09-07 13:13:28 +02:00
|
|
|
launchActivity(LoginActivity(), firstTime = true)
|
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 {
|
2021-03-19 10:34:43 +01:00
|
|
|
sendTraceDroidStackTracesIfExist("contact@pixeldroid.org", this)
|
|
|
|
|
2020-05-01 11:26:18 +02:00
|
|
|
setupDrawer()
|
2021-05-08 20:12:05 +02:00
|
|
|
val tabs: List<() -> Fragment> = listOf(
|
|
|
|
{
|
|
|
|
PostFeedFragment<HomeStatusDatabaseEntity>()
|
|
|
|
.apply {
|
|
|
|
arguments = Bundle().apply { putBoolean("home", true) }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ SearchDiscoverFragment() },
|
|
|
|
{ CameraFragment() },
|
|
|
|
{ NotificationsFragment() },
|
|
|
|
{
|
|
|
|
PostFeedFragment<PublicFeedStatusDatabaseEntity>()
|
|
|
|
.apply {
|
|
|
|
arguments = Bundle().apply { putBoolean("home", false) }
|
|
|
|
}
|
|
|
|
}
|
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)
|
2021-09-25 13:52:18 +02:00
|
|
|
|
|
|
|
val showNotification: Boolean = intent.getBooleanExtra(SHOW_NOTIFICATION_TAG, false)
|
|
|
|
|
|
|
|
if(showNotification){
|
|
|
|
binding.viewPager.currentItem = 3
|
|
|
|
}
|
2022-11-03 15:16:27 +01:00
|
|
|
if (ActivityCompat.checkSelfPermission(applicationContext,
|
|
|
|
Manifest.permission.POST_NOTIFICATIONS
|
|
|
|
) == PackageManager.PERMISSION_GRANTED
|
|
|
|
) enablePullNotifications(this)
|
|
|
|
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
|
|
notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
|
|
|
|
}
|
2021-09-25 13:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-03 15:16:27 +01:00
|
|
|
private val notificationPermissionLauncher = registerForActivityResult(
|
|
|
|
ActivityResultContracts.RequestPermission()
|
|
|
|
) { isGranted: Boolean ->
|
|
|
|
if (isGranted) enablePullNotifications(this)
|
|
|
|
}
|
|
|
|
|
2021-09-25 13:52:18 +02:00
|
|
|
// Checks if the activity was launched from a notification from another account than the
|
|
|
|
// current active one, and if so switches to that account
|
|
|
|
private fun notificationFromOtherUser(): Boolean {
|
|
|
|
val userOfNotification: String? = intent.extras?.getString(USER_NOTIFICATION_TAG)
|
|
|
|
val instanceOfNotification: String? = intent.extras?.getString(INSTANCE_NOTIFICATION_TAG)
|
|
|
|
if (userOfNotification != null && instanceOfNotification != null
|
|
|
|
&& (userOfNotification != user?.user_id
|
|
|
|
|| instanceOfNotification != user?.instance_uri)
|
|
|
|
) {
|
|
|
|
|
2021-09-25 21:24:31 +02:00
|
|
|
switchUser(userOfNotification, instanceOfNotification)
|
2021-09-25 13:52:18 +02:00
|
|
|
|
|
|
|
val newIntent = Intent(this, MainActivity::class.java)
|
|
|
|
newIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
|
|
|
|
|
|
if (intent.getBooleanExtra(SHOW_NOTIFICATION_TAG, false)) {
|
|
|
|
newIntent.putExtra(SHOW_NOTIFICATION_TAG, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
finish()
|
|
|
|
startActivity(newIntent)
|
|
|
|
return true
|
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
|
|
|
}
|
2021-09-25 13:52:18 +02:00
|
|
|
return false
|
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() {
|
2022-07-08 23:20:44 +02:00
|
|
|
binding.mainDrawerButton.setOnClickListener{
|
|
|
|
binding.drawerLayout.openDrawer(binding.drawer)
|
2020-09-13 23:35:09 +02:00
|
|
|
}
|
|
|
|
|
2020-05-19 09:49:34 +02:00
|
|
|
header = AccountHeaderView(this).apply {
|
2022-07-08 23:20:44 +02:00
|
|
|
attachToSliderView(binding.drawer)
|
2020-05-19 09:49:34 +02:00
|
|
|
headerBackgroundScaleType = ImageView.ScaleType.CENTER_CROP
|
|
|
|
currentHiddenInList = true
|
|
|
|
onAccountHeaderListener = { _: View?, profile: IProfile, current: Boolean ->
|
|
|
|
clickProfile(profile, current)
|
|
|
|
}
|
|
|
|
addProfile(ProfileSettingDrawerItem().apply {
|
|
|
|
identifier = ADD_ACCOUNT_IDENTIFIER
|
|
|
|
nameRes = R.string.add_account_name
|
|
|
|
descriptionRes = R.string.add_account_description
|
|
|
|
iconicsIcon = GoogleMaterial.Icon.gmd_add
|
|
|
|
}, 0)
|
|
|
|
dividerBelowHeader = false
|
|
|
|
closeDrawerOnProfileListClick = true
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
|
|
|
|
override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) {
|
2021-09-25 21:24:31 +02:00
|
|
|
Glide.with(this@MainActivity)
|
2020-05-19 09:49:34 +02:00
|
|
|
.load(uri)
|
|
|
|
.placeholder(placeholder)
|
|
|
|
.into(imageView)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun cancel(imageView: ImageView) {
|
2021-09-25 21:24:31 +02:00
|
|
|
Glide.with(this@MainActivity).clear(imageView)
|
2020-05-19 09:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun placeholder(ctx: Context, tag: String?): Drawable {
|
|
|
|
if (tag == DrawerImageLoader.Tags.PROFILE.name || tag == DrawerImageLoader.Tags.PROFILE_DRAWER_ITEM.name) {
|
2020-11-27 17:02:52 +01:00
|
|
|
return ContextCompat.getDrawable(ctx, R.drawable.ic_default_user)!!
|
2020-05-19 09:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return super.placeholder(ctx, tag)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
fillDrawerAccountInfo(user!!.user_id)
|
|
|
|
|
|
|
|
//after setting with the values in the db, we make sure to update the database and apply
|
|
|
|
//with the received one. This happens asynchronously.
|
|
|
|
getUpdatedAccount()
|
|
|
|
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.drawer.itemAdapter.add(
|
2020-05-19 09:49:34 +02:00
|
|
|
primaryDrawerItem {
|
|
|
|
nameRes = R.string.menu_account
|
|
|
|
iconicsIcon = GoogleMaterial.Icon.gmd_person
|
|
|
|
},
|
|
|
|
primaryDrawerItem {
|
|
|
|
nameRes = R.string.menu_settings
|
|
|
|
iconicsIcon = GoogleMaterial.Icon.gmd_settings
|
|
|
|
},
|
|
|
|
primaryDrawerItem {
|
|
|
|
nameRes = R.string.logout
|
|
|
|
iconicsIcon = GoogleMaterial.Icon.gmd_close
|
2023-11-03 18:49:44 +01:00
|
|
|
},
|
|
|
|
)
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.drawer.onDrawerItemClickListener = { v, drawerItem, position ->
|
2020-05-19 09:49:34 +02:00
|
|
|
when (position){
|
|
|
|
1 -> launchActivity(ProfileActivity())
|
|
|
|
2 -> launchActivity(SettingsActivity())
|
|
|
|
3 -> logOut()
|
|
|
|
}
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun logOut(){
|
2021-09-07 13:13:28 +02:00
|
|
|
finish()
|
2021-09-25 13:52:18 +02:00
|
|
|
|
|
|
|
removeNotificationChannelsFromAccount(applicationContext, user)
|
|
|
|
|
2021-01-05 00:38:16 +01:00
|
|
|
db.runInTransaction {
|
|
|
|
db.userDao().deleteActiveUsers()
|
|
|
|
|
|
|
|
val remainingUsers = db.userDao().getAll()
|
|
|
|
if (remainingUsers.isEmpty()){
|
|
|
|
//no more users, start first-time login flow
|
|
|
|
launchActivity(LoginActivity(), firstTime = true)
|
|
|
|
} else {
|
|
|
|
val newActive = remainingUsers.first()
|
2021-09-25 21:24:31 +02:00
|
|
|
db.userDao().activateUser(newActive.user_id, newActive.instance_uri)
|
2021-04-20 14:07:18 +02:00
|
|
|
apiHolder.setToCurrentUser()
|
2021-01-05 00:38:16 +01:00
|
|
|
//relaunch the app
|
|
|
|
launchActivity(MainActivity(), firstTime = true)
|
|
|
|
}
|
2020-05-19 09:49:34 +02:00
|
|
|
}
|
|
|
|
}
|
2022-08-03 22:28:20 +02:00
|
|
|
|
2020-07-26 20:56:01 +02:00
|
|
|
private fun getUpdatedAccount() {
|
2020-05-14 20:14:41 +02:00
|
|
|
if (hasInternet(applicationContext)) {
|
2020-05-01 11:26:18 +02:00
|
|
|
|
2020-12-29 19:34:48 +01:00
|
|
|
lifecycleScope.launchWhenCreated {
|
|
|
|
try {
|
2021-04-18 22:32:50 +02:00
|
|
|
val domain = user?.instance_uri.orEmpty()
|
|
|
|
val accessToken = user?.accessToken.orEmpty()
|
|
|
|
val refreshToken = user?.refreshToken
|
|
|
|
val clientId = user?.clientId.orEmpty()
|
|
|
|
val clientSecret = user?.clientSecret.orEmpty()
|
2021-04-20 14:07:18 +02:00
|
|
|
val api = apiHolder.api ?: apiHolder.setToCurrentUser()
|
2021-04-18 22:32:50 +02:00
|
|
|
|
|
|
|
val account = api.verifyCredentials()
|
2020-12-29 19:34:48 +01:00
|
|
|
addUser(db, account, domain, accessToken = accessToken, refreshToken = refreshToken, clientId = clientId, clientSecret = clientSecret)
|
|
|
|
fillDrawerAccountInfo(account.id!!)
|
2022-11-28 00:10:23 +01:00
|
|
|
} catch (exception: Exception) {
|
2020-12-29 19:34:48 +01:00
|
|
|
Log.e("ACCOUNT UPDATE:", exception.toString())
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 20:14:41 +02:00
|
|
|
}
|
2020-03-12 22:23:25 +01:00
|
|
|
}
|
2020-03-04 18:04:55 +01:00
|
|
|
|
2020-05-19 09:49:34 +02:00
|
|
|
//called when switching profiles, or when clicking on current profile
|
|
|
|
private fun clickProfile(profile: IProfile, current: Boolean): Boolean {
|
|
|
|
if(current){
|
|
|
|
launchActivity(ProfileActivity())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
//Clicked on add new account
|
|
|
|
if(profile.identifier == ADD_ACCOUNT_IDENTIFIER){
|
|
|
|
launchActivity(LoginActivity())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-09-25 21:24:31 +02:00
|
|
|
switchUser(profile.identifier.toString(), profile.tag as String)
|
2021-09-25 13:52:18 +02:00
|
|
|
|
2020-05-19 09:49:34 +02:00
|
|
|
val intent = Intent(this, MainActivity::class.java)
|
|
|
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
2021-09-07 13:13:28 +02:00
|
|
|
|
|
|
|
finish()
|
2020-05-19 09:49:34 +02:00
|
|
|
startActivity(intent)
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-09-25 21:24:31 +02:00
|
|
|
private fun switchUser(userId: String, instance_uri: String) {
|
2021-09-25 13:52:18 +02:00
|
|
|
db.userDao().deActivateActiveUsers()
|
2021-09-25 21:24:31 +02:00
|
|
|
db.userDao().activateUser(userId, instance_uri)
|
2021-09-25 13:52:18 +02:00
|
|
|
apiHolder.setToCurrentUser()
|
|
|
|
}
|
|
|
|
|
2020-05-19 09:49:34 +02:00
|
|
|
private inline fun primaryDrawerItem(block: PrimaryDrawerItem.() -> Unit): PrimaryDrawerItem {
|
|
|
|
return PrimaryDrawerItem()
|
|
|
|
.apply {
|
|
|
|
isSelectable = false
|
|
|
|
isIconTinted = true
|
|
|
|
}
|
|
|
|
.apply(block)
|
2022-07-08 23:20:44 +02:00
|
|
|
}
|
2020-05-19 09:49:34 +02:00
|
|
|
|
|
|
|
private fun fillDrawerAccountInfo(account: String) {
|
|
|
|
val users = db.userDao().getAll().toMutableList()
|
2020-12-19 13:22:45 +01:00
|
|
|
users.sortWith { l, r ->
|
2020-05-19 09:49:34 +02:00
|
|
|
when {
|
|
|
|
l.isActive && !r.isActive -> -1
|
|
|
|
r.isActive && !l.isActive -> 1
|
|
|
|
else -> 0
|
|
|
|
}
|
2020-12-19 13:22:45 +01:00
|
|
|
}
|
2020-05-19 09:49:34 +02:00
|
|
|
val profiles: MutableList<IProfile> = users.map { user ->
|
|
|
|
ProfileDrawerItem().apply {
|
|
|
|
isSelected = user.isActive
|
|
|
|
nameText = user.display_name
|
|
|
|
iconUrl = user.avatar_static
|
|
|
|
isNameShown = true
|
|
|
|
identifier = user.user_id.toLong()
|
2021-09-25 13:52:18 +02:00
|
|
|
descriptionText = user.fullHandle
|
2021-09-25 21:24:31 +02:00
|
|
|
tag = user.instance_uri
|
2020-05-19 09:49:34 +02:00
|
|
|
}
|
|
|
|
}.toMutableList()
|
|
|
|
|
|
|
|
// reuse the already existing "add account" item
|
2020-11-01 18:44:32 +01:00
|
|
|
header.profiles.orEmpty()
|
|
|
|
.filter { it.identifier == ADD_ACCOUNT_IDENTIFIER }
|
|
|
|
.take(1)
|
2020-11-06 14:49:49 +01:00
|
|
|
.forEach { profiles.add(it) }
|
2020-11-01 18:44:32 +01:00
|
|
|
|
2020-05-19 09:49:34 +02:00
|
|
|
header.clear()
|
|
|
|
header.profiles = profiles
|
|
|
|
header.setActiveProfile(account.toLong())
|
2020-05-14 20:14:41 +02:00
|
|
|
}
|
2020-05-01 11:26:18 +02:00
|
|
|
|
2021-05-09 23:49:11 +02:00
|
|
|
/**
|
|
|
|
* Use reflection to make it a bit harder to swipe between tabs
|
|
|
|
*/
|
|
|
|
private fun ViewPager2.reduceDragSensitivity() {
|
|
|
|
val recyclerViewField = ViewPager2::class.java.getDeclaredField("mRecyclerView")
|
|
|
|
recyclerViewField.isAccessible = true
|
|
|
|
val recyclerView = recyclerViewField.get(this) as RecyclerView
|
|
|
|
|
|
|
|
val touchSlopField = RecyclerView::class.java.getDeclaredField("mTouchSlop")
|
|
|
|
touchSlopField.isAccessible = true
|
|
|
|
val touchSlop = touchSlopField.get(recyclerView) as Int
|
2021-05-10 16:04:06 +02:00
|
|
|
touchSlopField.set(recyclerView, touchSlop*NestedScrollableHost.touchSlopModifier)
|
2021-05-09 23:49:11 +02:00
|
|
|
}
|
2020-05-19 09:49:34 +02:00
|
|
|
|
2021-05-08 20:12:05 +02:00
|
|
|
private fun setupTabs(tab_array: List<() -> Fragment>){
|
2021-05-09 23:49:11 +02:00
|
|
|
binding.viewPager.reduceDragSensitivity()
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.viewPager.adapter = object : FragmentStateAdapter(this) {
|
2020-03-13 11:48:45 +01:00
|
|
|
override fun createFragment(position: Int): Fragment {
|
2021-05-08 20:12:05 +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 {
|
2020-11-27 17:02:52 +01:00
|
|
|
return tab_array.size
|
2020-03-13 11:48:45 +01:00
|
|
|
}
|
|
|
|
}
|
2021-05-18 12:06:38 +02:00
|
|
|
|
2022-07-08 23:20:44 +02:00
|
|
|
binding.viewPager.registerOnPageChangeCallback(object : OnPageChangeCallback() {
|
|
|
|
override fun onPageSelected(position: Int) {
|
|
|
|
val selected = when(position){
|
|
|
|
0 -> R.id.page_1
|
|
|
|
1 -> R.id.page_2
|
|
|
|
2 -> R.id.page_3
|
2022-10-23 22:58:41 +02:00
|
|
|
3 -> {
|
|
|
|
setNotificationBadge(false)
|
|
|
|
R.id.page_4
|
|
|
|
}
|
2022-07-08 23:20:44 +02:00
|
|
|
4 -> R.id.page_5
|
|
|
|
else -> null
|
2021-05-18 12:06:38 +02:00
|
|
|
}
|
2022-07-08 23:20:44 +02:00
|
|
|
if (selected != null) {
|
|
|
|
binding.tabs.selectedItemId = selected
|
|
|
|
}
|
|
|
|
super.onPageSelected(position)
|
2021-05-18 12:06:38 +02:00
|
|
|
}
|
|
|
|
})
|
2020-11-27 17:02:52 +01:00
|
|
|
|
2022-07-08 23:20:44 +02:00
|
|
|
fun MenuItem.itemPos(): Int? {
|
|
|
|
return when(itemId){
|
|
|
|
R.id.page_1 -> 0
|
|
|
|
R.id.page_2 -> 1
|
|
|
|
R.id.page_3 -> 2
|
|
|
|
R.id.page_4 -> 3
|
|
|
|
R.id.page_5 -> 4
|
|
|
|
else -> null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
binding.tabs.setOnItemSelectedListener {item ->
|
|
|
|
item.itemPos()?.let {
|
|
|
|
binding.viewPager.currentItem = it
|
|
|
|
true
|
|
|
|
} ?: false
|
|
|
|
}
|
2022-10-23 22:58:41 +02:00
|
|
|
|
2022-07-08 23:20:44 +02:00
|
|
|
binding.tabs.setOnItemReselectedListener { item ->
|
|
|
|
item.itemPos()?.let { position ->
|
|
|
|
val page =
|
|
|
|
//No clue why this works but it does. F to pay respects
|
|
|
|
supportFragmentManager.findFragmentByTag("f$position")
|
|
|
|
(page as? CachedFeedFragment<*>)?.onTabReClicked()
|
|
|
|
}
|
|
|
|
}
|
2022-08-03 22:28:20 +02:00
|
|
|
|
|
|
|
// Fetch one notification to show a badge if there are new notifications
|
|
|
|
lifecycleScope.launch {
|
|
|
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
|
|
|
user?.let {
|
2022-10-23 22:58:41 +02:00
|
|
|
val lastNotification = db.notificationDao().latestNotification(it.user_id, it.instance_uri)
|
2022-08-03 22:28:20 +02:00
|
|
|
try {
|
|
|
|
val notification: List<Notification>? = apiHolder.api?.notifications(
|
2022-10-23 22:58:41 +02:00
|
|
|
min_id = lastNotification?.id,
|
|
|
|
limit = "20"
|
2022-08-03 22:28:20 +02:00
|
|
|
)
|
2022-10-23 22:58:41 +02:00
|
|
|
val filtered = notification?.filter { notification ->
|
|
|
|
lastNotification == null || (notification.created_at
|
|
|
|
?: Instant.MIN) > (lastNotification.created_at ?: Instant.MIN)
|
|
|
|
}
|
|
|
|
val numberOfNewNotifications = if((filtered?.size ?: 20) >= 20) null else filtered?.size
|
|
|
|
if(filtered?.isNotEmpty() == true ) setNotificationBadge(true, numberOfNewNotifications)
|
2022-11-28 00:10:23 +01:00
|
|
|
} catch (exception: Exception) {
|
2022-08-03 22:28:20 +02:00
|
|
|
return@repeatOnLifecycle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-08 23:20:44 +02:00
|
|
|
}
|
|
|
|
|
2022-10-23 22:58:41 +02:00
|
|
|
private fun setNotificationBadge(show: Boolean, count: Int? = null){
|
|
|
|
if(show){
|
|
|
|
val badge = binding.tabs.getOrCreateBadge(R.id.page_4)
|
|
|
|
if (count != null) badge.number = count
|
|
|
|
}
|
|
|
|
else binding.tabs.removeBadge(R.id.page_4)
|
|
|
|
}
|
|
|
|
|
2022-07-08 23:20:44 +02:00
|
|
|
fun BottomNavigationView.uncheckAllItems() {
|
|
|
|
menu.setGroupCheckable(0, true, false)
|
|
|
|
for (i in 0 until menu.size()) {
|
|
|
|
menu.getItem(i).isChecked = false
|
|
|
|
}
|
|
|
|
menu.setGroupCheckable(0, true, true)
|
2020-03-05 21:07:10 +01:00
|
|
|
}
|
|
|
|
|
2020-03-12 23:27:40 +01:00
|
|
|
/**
|
2020-07-26 20:56:01 +02:00
|
|
|
* Launches the given activity and put it as the current one
|
|
|
|
* @param firstTime to true means the task history will be reset (as if the app were
|
|
|
|
* launched anew into this activity)
|
2020-03-05 22:49:16 +01:00
|
|
|
*/
|
2020-05-19 09:49:34 +02:00
|
|
|
private fun launchActivity(activity: AppCompatActivity, firstTime: Boolean = false) {
|
2020-03-08 12:54:18 +01:00
|
|
|
val intent = Intent(this, activity::class.java)
|
2020-05-19 09:49:34 +02:00
|
|
|
|
|
|
|
if(firstTime){
|
|
|
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
|
|
}
|
2020-03-08 12:54:18 +01:00
|
|
|
startActivity(intent)
|
2020-03-05 22:49:16 +01:00
|
|
|
}
|
|
|
|
|
2020-03-12 23:27:40 +01:00
|
|
|
/**
|
2020-07-26 20:56:01 +02: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() {
|
2021-01-13 01:28:08 +01:00
|
|
|
if(binding.drawerLayout.isDrawerOpen(GravityCompat.START)){
|
|
|
|
binding.drawerLayout.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
|
|
|
}
|