Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create the main screen with new UX/UI using DrawerNavigation #186

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ android {

def versionMap = getVersionMap()

compileSdkVersion 28
compileSdkVersion 29
defaultConfig {
applicationId packageId
minSdkVersion 23
targetSdkVersion 28
targetSdkVersion 29
versionCode versionMap.code
versionName versionMap.name
testInstrumentationRunner "br.org.cesar.discordtime.stickysessions.MockTestRunner"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package br.org.cesar.discordtime.stickysessions

import androidx.test.InstrumentationRegistry

import androidx.test.platform.app.InstrumentationRegistry
class JsonReader {

fun readFromAssets(json: String): String =
InstrumentationRegistry.getContext().assets.open(json)
InstrumentationRegistry.getInstrumentation().targetContext.assets.open(json)
.bufferedReader().use { it.readText() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class MockTestRunner : AndroidJUnitRunner() {

@Throws(InstantiationException::class, IllegalAccessException::class, ClassNotFoundException::class)
override fun newApplication(cl: ClassLoader, className: String, context: Context): Application {
return super.newApplication(cl, TestApplication::class.java!!.name, context)
return super.newApplication(cl, TestApplication::class.java.name, context)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package br.org.cesar.discordtime.stickysessions.app

import androidx.test.InstrumentationRegistry
import androidx.test.platform.app.InstrumentationRegistry
import br.org.cesar.discordtime.stickysessions.injectors.MockHttpModule
import br.org.cesar.discordtime.stickysessions.injectors.MockServerModule
import br.org.cesar.discordtime.stickysessions.injectors.MockThreadModule
Expand All @@ -13,23 +13,26 @@ class TestApplication : StickySessionApplication() {

override fun configureMainInjectorBuilder() {
mLobbyComponentBuilder = DaggerLobbyComponent.builder()
.contextModule(ContextModule(InstrumentationRegistry.getContext()))
.contextModule(ContextModule(InstrumentationRegistry
.getInstrumentation().targetContext))
.threadModule(MockThreadModule())
.serverModule(MockServerModule())
.httpModule(MockHttpModule())
}

override fun configureSessionInjectorBuilder() {
mSessionComponentBuilder = DaggerSessionComponent.builder()
.contextModule(ContextModule(InstrumentationRegistry.getContext()))
.contextModule(ContextModule(InstrumentationRegistry
.getInstrumentation().targetContext))
.threadModule(MockThreadModule())
.serverModule(MockServerModule())
.httpModule(MockHttpModule())
}

override fun configureSessionListInjectorBuilder() {
mSessionListBuilder = DaggerListSessionComponent.builder()
.contextModule(ContextModule(InstrumentationRegistry.getContext()))
.contextModule(ContextModule(InstrumentationRegistry
.getInstrumentation().targetContext))
.threadModule(MockThreadModule())
.serverModule(MockServerModule())
.httpModule(MockHttpModule())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import androidx.test.ext.junit.runners.AndroidJUnit4
import br.org.cesar.discordtime.stickysessions.MockServerDispatcher
import br.org.cesar.discordtime.stickysessions.R
import br.org.cesar.discordtime.stickysessions.ui.ExtraNames
Expand All @@ -18,7 +18,6 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(AndroidJUnit4::class)
@LargeTest
class ListSessionsActivityEspressoTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import androidx.test.ext.junit.runners.AndroidJUnit4
import br.org.cesar.discordtime.stickysessions.R
import org.junit.Rule
import org.junit.Test
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity
android:name=".ui.meeting.MeetingActivity"
android:screenOrientation="${orientation}" />
android:name=".ui.main.MainActivity"
android:screenOrientation="${orientation}" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity
android:name=".ui.session.SessionActivity"
android:screenOrientation="${orientation}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import br.org.cesar.discordtime.stickysessions.ui.list.ListSessionsActivity;
import br.org.cesar.discordtime.stickysessions.ui.lobby.LobbyActivity;
import br.org.cesar.discordtime.stickysessions.ui.login.LoginActivity;
import br.org.cesar.discordtime.stickysessions.ui.meeting.MeetingActivity;
import br.org.cesar.discordtime.stickysessions.ui.meeting.MeetingFragment;
import br.org.cesar.discordtime.stickysessions.ui.session.SessionActivity;
import io.fabric.sdk.android.Fabric;

Expand Down Expand Up @@ -77,8 +77,8 @@ public void inject(ListSessionsActivity activity) {
mSessionListBuilder.build().inject(activity);
}

public void inject(MeetingActivity activity) {
mMeetingComponentBuilder.build().inject(activity);
public void inject(MeetingFragment fragment) {
mMeetingComponentBuilder.build().inject(fragment);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import br.org.cesar.discordtime.stickysessions.injectors.modules.ServerModule;
import br.org.cesar.discordtime.stickysessions.injectors.modules.SessionModule;
import br.org.cesar.discordtime.stickysessions.injectors.modules.ThreadModule;
import br.org.cesar.discordtime.stickysessions.ui.meeting.MeetingActivity;
import br.org.cesar.discordtime.stickysessions.ui.meeting.MeetingFragment;
import dagger.Component;

@Component(modules = {
Expand All @@ -32,5 +32,5 @@
AuthModule.class
})
public interface MeetingComponent {
void inject(MeetingActivity activity);
void inject(MeetingFragment activity);
haldny marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inject(MeetingFragment fragment)

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import br.org.cesar.discordtime.stickysessions.ui.list.ListSessionsActivity;
import br.org.cesar.discordtime.stickysessions.ui.lobby.LobbyActivity;
import br.org.cesar.discordtime.stickysessions.ui.login.LoginActivity;
import br.org.cesar.discordtime.stickysessions.ui.meeting.MeetingActivity;
import br.org.cesar.discordtime.stickysessions.ui.main.MainActivity;
import br.org.cesar.discordtime.stickysessions.ui.session.SessionActivity;

public class ViewStarter implements IViewStarter {
Expand All @@ -22,9 +22,9 @@ public class ViewStarter implements IViewStarter {
new HashMap<String, Class<? extends Activity>> (){{
put(ViewNames.LOGIN_ACTIVITY, LoginActivity.class);
put(ViewNames.LOBBY_ACTIVITY, LobbyActivity.class);
put(ViewNames.MEETING_ACTIVITY, MeetingActivity.class);
put(ViewNames.SESSION_ACTIVITY, SessionActivity.class);
put(ViewNames.LIST_ACTIVITY, ListSessionsActivity.class);
put(ViewNames.MEETING_ACTIVITY, MainActivity.class);
}};

public void goNext(Context context, String activityName, boolean shouldClearStack)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import br.org.cesar.discordtime.stickysessions.navigation.wrapper.IBundle
interface MeetingContract {

interface Presenter {
fun attachView(view: MeetingContract.View)
fun attachView(view: View)
fun detachView()
fun onResume()
fun enterOnMeeting(meetingItem: MeetingItem)
Expand All @@ -16,7 +16,7 @@ interface MeetingContract {
interface View {
fun startLoadingMeetings()
fun stopLoadingMeetings()
fun showError(message: String)
fun showError(message: String?)
fun showMeetings(meetings: MutableList<MeetingItem>)
fun getName(): String
@Throws(InvalidViewNameException::class)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package br.org.cesar.discordtime.stickysessions.ui

object ViewNames {
const val LOGIN_ACTIVITY = "login_activity"
const val LOBBY_ACTIVITY = "lobby_activity"
const val MEETING_ACTIVITY = "meeting_activity"
const val SESSION_ACTIVITY = "session_activity"
const val LIST_ACTIVITY = "list_activity"
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class LobbyActivity extends AppCompatActivity implements LobbyContract.Vi
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.activity_lobby);

((StickySessionApplication) getApplication()).inject(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class LoginActivity : AppCompatActivity() {

// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
try {
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
// Google Sign In was successful, authenticate with Firebase
val account = task.getResult(ApiException::class.java)
firebaseAuthWithGoogle(account!!)
Expand All @@ -127,7 +127,6 @@ class LoginActivity : AppCompatActivity() {
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
mLogger.d(TAG, "signInWithCredential:success")
val user = auth.currentUser
// next activity
goNext()
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package br.org.cesar.discordtime.stickysessions.ui.main

import android.os.Build
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.TextView
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.GravityCompat
import br.org.cesar.discordtime.stickysessions.R
import br.org.cesar.discordtime.stickysessions.ui.meeting.MeetingFragment
import com.google.android.material.navigation.NavigationView
import com.google.android.material.snackbar.Snackbar

import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_main_app_bar.*

class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {

private lateinit var mToolbarTitle: TextView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
configureToolbar()

fab.setOnClickListener { view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
haldny marked this conversation as resolved.
Show resolved Hide resolved
}

supportFragmentManager.beginTransaction()
.replace(R.id.main_container, MeetingFragment()).commit()
}

private fun configureToolbar() {
val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)

supportActionBar?.apply {
setDisplayShowHomeEnabled(true)
setDisplayHomeAsUpEnabled(true)
}

mToolbarTitle = findViewById(R.id.toolbar_title)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i meant:

mToolbarTitle = findViewById(R.id.toolbar_title).apply {
text = getString(R.string.nav_header_desc)
}

mToolbarTitle.apply {
text = getString(R.string.nav_menu_meetings)
}

val toggle = ActionBarDrawerToggle(
this, drawer_layout, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close
)

drawer_layout.addDrawerListener(toggle)
toggle.syncState()

nav_view.setNavigationItemSelectedListener(this)
}

override fun onBackPressed() {
if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
drawer_layout.closeDrawer(GravityCompat.START)
} else {
super.onBackPressed()
}
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.drawer_menu, menu)

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
val icon = menu.findItem(R.id.notification_menu).icon
val drawable = DrawableCompat.wrap(icon)
DrawableCompat.setTint(drawable, ContextCompat.getColor(this, R.color.coral))
menu.findItem(R.id.notification_menu).apply {
setIcon(drawable)
}
}

return true
}

override fun onNavigationItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.nav_meetings -> {
showMeetingFragment()
}
R.id.nav_about -> {
haldny marked this conversation as resolved.
Show resolved Hide resolved
}
R.id.nav_settings -> {
haldny marked this conversation as resolved.
Show resolved Hide resolved
}
}

drawer_layout.closeDrawer(GravityCompat.START)
return true
}

private fun showMeetingFragment() {
supportFragmentManager.beginTransaction()
.replace(R.id.main_container, MeetingFragment()).commit()
}

}
Loading