diff --git a/app/src/androidTest/java/com/h/pixeldroid/LoginInstrumentedTest.kt b/app/src/androidTest/java/com/h/pixeldroid/LoginInstrumentedTest.kt index d24fb384..e9144da2 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/LoginInstrumentedTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/LoginInstrumentedTest.kt @@ -1,6 +1,7 @@ package com.h.pixeldroid import android.app.Activity +import android.content.Context import android.content.Intent import android.content.Intent.ACTION_VIEW import android.net.Uri @@ -17,6 +18,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.ActivityTestRule import org.hamcrest.CoreMatchers.allOf import org.hamcrest.CoreMatchers.anyOf @@ -90,6 +92,9 @@ class AfterIntent { @Before fun setup() { + val preferences = InstrumentationRegistry.getInstrumentation() + .targetContext.getSharedPreferences("com.h.pixeldroid.pref", Context.MODE_PRIVATE) + preferences.edit().putString("domain", "http://localhost").apply() val intent = Intent(ACTION_VIEW, Uri.parse("oauth2redirect://com.h.pixeldroid?code=sdfdqsf")) launchedActivity = rule.launchActivity(intent) } diff --git a/app/src/androidTest/java/com/h/pixeldroid/ProfileTest.kt b/app/src/androidTest/java/com/h/pixeldroid/MyProfileTest.kt similarity index 89% rename from app/src/androidTest/java/com/h/pixeldroid/ProfileTest.kt rename to app/src/androidTest/java/com/h/pixeldroid/MyProfileTest.kt index 85449545..355a7b00 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/ProfileTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/MyProfileTest.kt @@ -1,22 +1,17 @@ package com.h.pixeldroid import android.content.Context -import androidx.core.view.get import androidx.test.core.app.ActivityScenario import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions -import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry -import com.h.pixeldroid.objects.Account -import kotlinx.android.synthetic.main.activity_main.* import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer - import org.junit.Before import org.junit.Rule import org.junit.Test @@ -24,7 +19,7 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) -class ProfileTest { +class MyProfileTest { private val accountJson = "{\n" + " \"id\": \"1450\",\n" + " \"username\": \"deerbard_photo\",\n" + @@ -52,7 +47,6 @@ class ProfileTest { var activityRule: ActivityScenarioRule = ActivityScenarioRule(MainActivity::class.java) - @Before fun before(){ val server = MockWebServer() @@ -71,9 +65,7 @@ class ProfileTest { ViewActions.swipeLeft() ).perform(ViewActions.swipeLeft()) Thread.sleep(1000) - onView(withId(R.id.followers)).check(matches(withText("Followers"))) - onView(withId(R.id.accountName)).check(matches(withText("deerbard_photo"))) - - + onView(withId(R.id.nbFollowersTextView)).check(matches(withText("68\nFollowers"))) + onView(withId(R.id.accountNameTextView)).check(matches(withText("deerbard_photo"))) } -} \ No newline at end of file +} diff --git a/app/src/androidTest/java/com/h/pixeldroid/SwipeTest.kt b/app/src/androidTest/java/com/h/pixeldroid/SwipeTest.kt index 4a6c22a5..341343b6 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/SwipeTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/SwipeTest.kt @@ -34,7 +34,6 @@ class SwipeTest { @Test fun swipingRightOnHomepageShowsSettings() { onView(withId(R.id.view_pager)).perform(swipeLeft()).perform(swipeLeft()).perform(swipeLeft()).perform(swipeLeft()) - onView(withId(R.id.nbFollowers)).check(matches(isDisplayed())) - + onView(withId(R.id.nbFollowersTextView)).check(matches(isDisplayed())) } } \ No newline at end of file diff --git a/app/src/main/java/com/h/pixeldroid/MainActivity.kt b/app/src/main/java/com/h/pixeldroid/MainActivity.kt index 7ec3e49b..f05dd2a1 100644 --- a/app/src/main/java/com/h/pixeldroid/MainActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/MainActivity.kt @@ -17,7 +17,8 @@ import com.google.android.material.navigation.NavigationView import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayoutMediator import com.h.pixeldroid.fragments.HomeFragment -import com.h.pixeldroid.fragments.ProfileFragment +import com.h.pixeldroid.fragments.MyProfileFragment + class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener { @@ -26,7 +27,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte private lateinit var tabLayout: TabLayout private lateinit var preferences: SharedPreferences - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) @@ -45,7 +45,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte val navigationView: NavigationView = findViewById(R.id.nav_view) navigationView.setNavigationItemSelectedListener(this) - val tabs = arrayOf(HomeFragment(), Fragment(), Fragment(), Fragment(), ProfileFragment()) + val tabs = arrayOf(HomeFragment(), Fragment(), Fragment(), Fragment(), MyProfileFragment()) + setupTabs(tabs) } diff --git a/app/src/main/java/com/h/pixeldroid/fragments/ProfileFragment.kt b/app/src/main/java/com/h/pixeldroid/fragments/MyProfileFragment.kt similarity index 68% rename from app/src/main/java/com/h/pixeldroid/fragments/ProfileFragment.kt rename to app/src/main/java/com/h/pixeldroid/fragments/MyProfileFragment.kt index 05995fba..904676b1 100644 --- a/app/src/main/java/com/h/pixeldroid/fragments/ProfileFragment.kt +++ b/app/src/main/java/com/h/pixeldroid/fragments/MyProfileFragment.kt @@ -1,15 +1,17 @@ package com.h.pixeldroid.fragments import android.content.Context +import android.content.Intent import android.content.SharedPreferences - import android.graphics.Typeface +import android.net.Uri import android.os.Bundle import android.util.Log import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Button import android.widget.ImageView import android.widget.TextView import com.bumptech.glide.Glide @@ -17,12 +19,12 @@ import com.h.pixeldroid.BuildConfig import com.h.pixeldroid.R import com.h.pixeldroid.api.PixelfedAPI import com.h.pixeldroid.objects.Account -import com.h.pixeldroid.objects.Status import retrofit2.Call import retrofit2.Callback import retrofit2.Response -class ProfileFragment : Fragment() { + +class MyProfileFragment : Fragment() { private lateinit var preferences: SharedPreferences override fun onCreateView( @@ -32,7 +34,12 @@ class ProfileFragment : Fragment() { preferences = this.activity!!.getSharedPreferences( "${BuildConfig.APPLICATION_ID}.pref", Context.MODE_PRIVATE ) - return inflater.inflate(R.layout.fragment_profile, container, false) + val view = inflater.inflate(R.layout.fragment_my_profile, container, false) + + val editButton: Button = view.findViewById(R.id.editButton) + editButton.setOnClickListener((View.OnClickListener { onClickEditButton() })) + + return view } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -44,11 +51,10 @@ class ProfileFragment : Fragment() { pixelfedAPI.verifyCredentials("Bearer $accessToken") .enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { - if (response.code() == 200) { + if(response.code() == 200) { val account = response.body()!! setContent(view, account) - } } @@ -60,31 +66,42 @@ class ProfileFragment : Fragment() { private fun setContent(view: View, account: Account) { // ImageView : profile picture - val profilePicture = view.findViewById(R.id.profilePicture) + val profilePicture = view.findViewById(R.id.profilePictureImageView) Glide.with(view.context).load(account.avatar).into(profilePicture) - // TextView : description / bio - val description = view.findViewById(R.id.description) + val description = view.findViewById(R.id.descriptionTextView) description.text = account.note // TextView : account name - val accountName = view.findViewById(R.id.accountName) + val accountName = view.findViewById(R.id.accountNameTextView) accountName.text = account.username // TextView : number of posts - val nbPosts = view.findViewById(R.id.nbPosts) - nbPosts.text = account.statuses_count.toString() + val nbPosts = view.findViewById(R.id.nbPostsTextView) + nbPosts.text = account.statuses_count.toString() + "\nPosts" nbPosts.setTypeface(null, Typeface.BOLD) // TextView : number of followers - val nbFollowers = view.findViewById(R.id.nbFollowers) - nbFollowers.text = account.followers_count.toString() + val nbFollowers = view.findViewById(R.id.nbFollowersTextView) + nbFollowers.text = account.followers_count.toString() + "\nFollowers" nbFollowers.setTypeface(null, Typeface.BOLD) // TextView : number of following - val nbFollowing = view.findViewById(R.id.nbFollowing) - nbFollowing.text = account.following_count.toString() + val nbFollowing = view.findViewById(R.id.nbFollowingTextView) + nbFollowing.text = account.following_count.toString() + "\nFollowing" nbFollowing.setTypeface(null, Typeface.BOLD) } + + private fun onClickEditButton() { + val url = "${preferences.getString("domain", "")}/settings/home" + + val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + if(activity != null && browserIntent.resolveActivity(activity!!.packageManager) != null) { + startActivity(browserIntent) + } else { + val text = "Cannot open this link" + Log.e("ProfileFragment", text) + } + } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 804305ab..7657f7a8 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -9,6 +9,7 @@ tools:openDrawer="start" tools:context="com.h.pixeldroid.MainActivity"> + + + + + + + + + + + + + + + + + + + + +