Merge branch 'master' into feature/upload-pictures

This commit is contained in:
Ulysse Widmer 2020-03-18 01:19:04 +09:00
commit 0b681d9b6b
12 changed files with 122 additions and 240 deletions

File diff suppressed because one or more lines are too long

View File

@ -61,27 +61,27 @@ class LoginInstrumentedTest {
} }
} }
//@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
//class LoginCheckIntent { class LoginCheckIntent {
// @get:Rule @get:Rule
// val intentsTestRule = IntentsTestRule(LoginActivity::class.java) val intentsTestRule = IntentsTestRule(LoginActivity::class.java)
//
// @Test @Test
// fun launchesIntent() { fun launchesIntent() {
// val expectedIntent: Matcher<Intent> = allOf( val expectedIntent: Matcher<Intent> = allOf(
// hasAction(ACTION_VIEW), hasAction(ACTION_VIEW),
// hasDataString(containsString("pixelfed.social")) hasDataString(containsString("pixelfed.social"))
// ) )
//
// onView(withId(R.id.editText)).perform(ViewActions.replaceText("pixelfed.social"), ViewActions.closeSoftKeyboard()) onView(withId(R.id.editText)).perform(ViewActions.replaceText("pixelfed.social"), ViewActions.closeSoftKeyboard())
// onView(withId(R.id.connect_instance_button)).perform(click()) onView(withId(R.id.connect_instance_button)).perform(click())
//
// Thread.sleep(5000) Thread.sleep(5000)
//
// intended(expectedIntent) intended(expectedIntent)
//
// } }
//} }
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class AfterIntent { class AfterIntent {

File diff suppressed because one or more lines are too long

View File

@ -1,72 +0,0 @@
package com.h.pixeldroid
import android.content.Context
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
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 okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
//@RunWith(AndroidJUnit4::class)
class MyProfileTest {
/* private val accountJson = "{\n" +
" \"id\": \"1450\",\n" +
" \"username\": \"deerbard_photo\",\n" +
" \"acct\": \"deerbard_photo\",\n" +
" \"display_name\": \"deerbard photography\",\n" +
" \"locked\": false,\n" +
" \"created_at\": \"2018-08-01T12:58:21.000000Z\",\n" +
" \"followers_count\": 68,\n" +
" \"following_count\": 27,\n" +
" \"statuses_count\": 72,\n" +
" \"note\": \"\",\n" +
" \"url\": \"https://pixelfed.social/deerbard_photo\",\n" +
" \"avatar\": \"https://pixelfed.social/storage/avatars/000/000/001/450/SMSep5NoabDam1W8UDMh_avatar.png?v=4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a\",\n" +
" \"avatar_static\": \"https://pixelfed.social/storage/avatars/000/000/001/450/SMSep5NoabDam1W8UDMh_avatar.png?v=4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a\",\n" +
" \"header\": \"\",\n" +
" \"header_static\": \"\",\n" +
" \"emojis\": [],\n" +
" \"moved\": null,\n" +
" \"fields\": null,\n" +
" \"bot\": false,\n" +
" \"software\": \"pixelfed\",\n" +
" \"is_admin\": false\n" +
" }"
@get:Rule
var activityRule: ActivityScenarioRule<MainActivity>
= ActivityScenarioRule(MainActivity::class.java)
@Before
fun before(){
val server = MockWebServer()
server.enqueue(MockResponse().addHeader("Content-Type", "application/json; charset=utf-8").setBody(accountJson))
server.start()
val baseUrl = server.url("")
val preferences = InstrumentationRegistry.getInstrumentation()
.targetContext.getSharedPreferences("com.h.pixeldroid.pref", Context.MODE_PRIVATE)
preferences.edit().putString("accessToken", "azerty").apply()
preferences.edit().putString("domain", baseUrl.toString()).apply()
ActivityScenario.launch(MainActivity::class.java)
}
@Test
fun testFollowersTextView() {
onView(withId(R.id.view_pager)).perform(ViewActions.swipeLeft()).perform(ViewActions.swipeLeft()).perform(
ViewActions.swipeLeft()
).perform(ViewActions.swipeLeft())
Thread.sleep(1000)
onView(withId(R.id.nbFollowersTextView)).check(matches(withText("68\nFollowers")))
onView(withId(R.id.accountNameTextView)).check(matches(withText("deerbard_photo")))
}*/
}

View File

@ -44,7 +44,6 @@
android:scheme="@string/auth_scheme" /> android:scheme="@string/auth_scheme" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".FeedActivity" />
</application> </application>
</manifest> </manifest>

View File

@ -1,64 +0,0 @@
package com.h.pixeldroid
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.h.pixeldroid.api.PixelfedAPI
import com.h.pixeldroid.models.Post
import com.h.pixeldroid.models.Post.Companion.POST_FRAG_TAG
import com.h.pixeldroid.objects.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
class FeedActivity : AppCompatActivity() {
lateinit var feed : RecyclerView
lateinit var adapter : FeedRecyclerViewAdapter
var posts : List<Post> = ArrayList()
fun setContent(newPosts : ArrayList<Post>) {
feed = findViewById(R.id.feedList)
feed?.setHasFixedSize(true)
feed?.layoutManager = LinearLayoutManager(this)
posts = newPosts
adapter = FeedRecyclerViewAdapter(context = this)
feed?.adapter = adapter
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_feed)
var statuses: ArrayList<Status>? = null
val BASE_URL = "https://pixelfed.de/"
val pixelfedAPI = PixelfedAPI.create(BASE_URL)
val newPosts = ArrayList<Post>()
pixelfedAPI.timelinePublic(null, null, null, null, null)
.enqueue(object : Callback<List<Status>> {
override fun onResponse(call: Call<List<Status>>, response: Response<List<Status>>) {
if (response.code() == 200) {
statuses = response.body() as ArrayList<Status>?
if(!statuses.isNullOrEmpty()) {
for (status in statuses!!) {
newPosts.add(Post(status))
}
setContent(newPosts)
Log.e("POSTS", newPosts.toString())
}
}
}
override fun onFailure(call: Call<List<Status>>, t: Throwable) {
Log.e("Ouch, not OK", t.toString())
}
})
}
}

View File

@ -1,17 +1,15 @@
package com.h.pixeldroid package com.h.pixeldroid.fragments
import android.content.Context import android.content.Context
import android.graphics.Typeface import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.util.DisplayMetrics import android.util.DisplayMetrics
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.WindowManager
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.annotation.Dimension import com.h.pixeldroid.R
import com.h.pixeldroid.models.Post import com.h.pixeldroid.models.Post
import com.h.pixeldroid.utils.ImageConverter.Companion.setDefaultImage import com.h.pixeldroid.utils.ImageConverter.Companion.setDefaultImage
import com.h.pixeldroid.utils.ImageConverter.Companion.setImageViewFromURL import com.h.pixeldroid.utils.ImageConverter.Companion.setImageViewFromURL

View File

@ -12,7 +12,6 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.h.pixeldroid.BuildConfig import com.h.pixeldroid.BuildConfig
import com.h.pixeldroid.FeedRecyclerViewAdapter
import com.h.pixeldroid.R import com.h.pixeldroid.R
import com.h.pixeldroid.api.PixelfedAPI import com.h.pixeldroid.api.PixelfedAPI
import com.h.pixeldroid.models.Post import com.h.pixeldroid.models.Post
@ -56,7 +55,7 @@ class HomeFragment : Fragment() {
var statuses: ArrayList<Status>? = null var statuses: ArrayList<Status>? = null
val newPosts = ArrayList<Post>() val newPosts = ArrayList<Post>()
pixelfedAPI.timelinePublic(null, null, null, null, null) pixelfedAPI.timelineHome("Bearer $accessToken")
.enqueue(object : Callback<List<Status>> { .enqueue(object : Callback<List<Status>> {
override fun onResponse(call: Call<List<Status>>, response: Response<List<Status>>) { override fun onResponse(call: Call<List<Status>>, response: Response<List<Status>>) {
if (response.code() == 200) { if (response.code() == 200) {
@ -66,14 +65,13 @@ class HomeFragment : Fragment() {
newPosts.add(Post(status)) newPosts.add(Post(status))
} }
setContent(newPosts) setContent(newPosts)
Log.e("POSTS", newPosts.toString())
} }
} }
} }
override fun onFailure(call: Call<List<Status>>, t: Throwable) { override fun onFailure(call: Call<List<Status>>, t: Throwable) {
Log.e("Ouch, not OK", t.toString()) Log.e("HomeFragment", t.toString())
} }
}) })
} }

View File

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FeedActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/feedList"
android:name="com.h.pixeldroid.FeedFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context=".FeedActivity"
tools:listitem="@layout/post_fragment" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -9,5 +9,4 @@
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager" app:layoutManager="LinearLayoutManager"
tools:context=".FeedActivity"
tools:listitem="@layout/post_fragment" /> tools:listitem="@layout/post_fragment" />

View File

@ -14,7 +14,6 @@
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager" app:layoutManager="LinearLayoutManager"
tools:context=".FeedActivity"
tools:listitem="@layout/post_fragment" /> tools:listitem="@layout/post_fragment" />
<LinearLayout <LinearLayout

View File

@ -54,7 +54,6 @@ tools:context=".fragments.PostFragment">
android:id="@+id/postPicture" android:id="@+id/postPicture"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_foreground"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>