Merge pull request #60 from H-PixelDroid/feature/upload-pictures
Upload picture implemented
This commit is contained in:
commit
55cb729a2d
app/src
@ -1,17 +1,17 @@
|
||||
package com.h.pixeldroid
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions.swipeLeft
|
||||
import androidx.test.espresso.action.ViewActions.swipeRight
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.ext.junit.rules.ActivityScenarioRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
|
||||
import androidx.test.rule.ActivityTestRule
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@ -31,10 +31,30 @@ class SwipeTest {
|
||||
ActivityScenario.launch(MainActivity::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun swipingRightOnHomepageShowsSettings() {
|
||||
onView(withId(R.id.view_pager)).perform(swipeLeft()).perform(swipeLeft()).perform(swipeLeft()).perform(swipeLeft())
|
||||
onView(withId(R.id.nbFollowersTextView)).check(matches(isDisplayed()))
|
||||
fun swipingLeftOnSearchShowsCameraFragment() {
|
||||
onView(withId(R.id.main_activity_main_linear_layout))
|
||||
.perform(swipeLeft()) // go to search
|
||||
.perform(swipeLeft())
|
||||
onView(withId(R.id.camera_fragment_main_linear_layout)).check(matches(isDisplayed()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun swipingRightOnNotificationsShowsCameraFragment() {
|
||||
onView(withId(R.id.main_activity_main_linear_layout))
|
||||
.perform(swipeLeft())
|
||||
.perform(swipeLeft())
|
||||
.perform(swipeLeft()) // go to notifications
|
||||
.perform(swipeRight())
|
||||
onView(withId(R.id.camera_fragment_main_linear_layout)).check(matches(isDisplayed()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun swipingLeftShowsProfileFragment() {
|
||||
onView(withId(R.id.view_pager))
|
||||
.perform(swipeLeft())
|
||||
.perform(swipeLeft())
|
||||
.perform(swipeLeft())
|
||||
.perform(swipeLeft())
|
||||
onView(withId(R.id.nbFollowersTextView)).check(matches(isDisplayed()))
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
package="com.h.pixeldroid">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -16,6 +16,7 @@ import androidx.viewpager2.widget.ViewPager2
|
||||
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.CameraFragment
|
||||
import com.h.pixeldroid.fragments.HomeFragment
|
||||
import com.h.pixeldroid.fragments.MyProfileFragment
|
||||
import com.h.pixeldroid.fragments.NotificationsFragment
|
||||
@ -46,11 +47,11 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||
navigationView.setNavigationItemSelectedListener(this)
|
||||
|
||||
val tabs = arrayOf(HomeFragment(),
|
||||
Fragment(), Fragment(),
|
||||
Fragment(),
|
||||
CameraFragment(),
|
||||
NotificationsFragment(),
|
||||
MyProfileFragment())
|
||||
|
||||
|
||||
setupTabs(tabs)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
package com.h.pixeldroid.fragments
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
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 com.h.pixeldroid.R
|
||||
|
||||
const val PICK_IMAGE_REQUEST = 1
|
||||
const val TAG = "Camera Fragment"
|
||||
|
||||
class CameraFragment : Fragment() {
|
||||
|
||||
private var uploadedPictureView: ImageView? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val view = inflater.inflate(R.layout.fragment_camera, container, false)
|
||||
val uploadPictureButton: Button = view.findViewById(R.id.upload_picture_button)
|
||||
uploadedPictureView = view.findViewById(R.id.uploaded_picture_view)
|
||||
uploadPictureButton.setOnClickListener{
|
||||
uploadPicture()
|
||||
}
|
||||
|
||||
// Inflate the layout for this fragment
|
||||
return view
|
||||
}
|
||||
|
||||
private fun uploadPicture() {
|
||||
Intent().apply {
|
||||
type = "image/*"
|
||||
action = Intent.ACTION_GET_CONTENT
|
||||
startActivityForResult(
|
||||
Intent.createChooser(this, "Select a Picture"), PICK_IMAGE_REQUEST
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == PICK_IMAGE_REQUEST && resultCode == Activity.RESULT_OK) {
|
||||
if(data == null || data.data == null){
|
||||
Log.w(TAG, "No picture uploaded")
|
||||
return
|
||||
}
|
||||
uploadedPictureView?.setImageURI(data.data)
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/main_activity_main_linear_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
29
app/src/main/res/layout/fragment_camera.xml
Normal file
29
app/src/main/res/layout/fragment_camera.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/camera_fragment_main_linear_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal"
|
||||
tools:context=".fragments.CameraFragment"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/upload_picture_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="15dp"
|
||||
android:layout_margin="15dp"
|
||||
android:text="@string/upload_a_picture"
|
||||
android:background="@color/colorPrimary"
|
||||
android:textColor="@color/cardview_light_background"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/uploaded_picture_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="15dp"
|
||||
tools:srcCompat="@tools:sample/avatars" />
|
||||
|
||||
</LinearLayout>
|
@ -58,6 +58,7 @@
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
<string name="start_login">Start Login</string>
|
||||
<string name="no_username">No Username</string>
|
||||
<string name="upload_a_picture">Upload a picture</string>
|
||||
<string name="followed_notification">%1$s followed you</string>
|
||||
<string name="mention_notification">%1$s mentioned you</string>
|
||||
<string name="shared_notification">%1$s shared your post</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user