diff --git a/project/app/build.gradle b/project/app/build.gradle index ddbd7d7f..0cee2742 100644 --- a/project/app/build.gradle +++ b/project/app/build.gradle @@ -27,10 +27,10 @@ android { compileSdkVersion 26 defaultConfig { applicationId "com.nexte.nexte" - minSdkVersion 22 + minSdkVersion 18 targetSdkVersion 26 - versionCode 5 - versionName "0.5" + versionCode 6 + versionName "0.6" multiDexEnabled true testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } diff --git a/project/app/src/androidTest/java/com/nexte/nexte/CommentsViewTest.java b/project/app/src/androidTest/java/com/nexte/nexte/CommentsViewTest.java deleted file mode 100644 index 7b8250d5..00000000 --- a/project/app/src/androidTest/java/com/nexte/nexte/CommentsViewTest.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.nexte.nexte; - - -import android.support.test.espresso.ViewInteraction; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; -import android.test.suitebuilder.annotation.LargeTest; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewParent; - -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.action.ViewActions.click; -import static android.support.test.espresso.action.ViewActions.scrollTo; -import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; -import static android.support.test.espresso.matcher.ViewMatchers.withClassName; -import static android.support.test.espresso.matcher.ViewMatchers.withId; -import static android.support.test.espresso.matcher.ViewMatchers.withText; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.is; - -@LargeTest -@RunWith(AndroidJUnit4.class) -public class CommentsViewTest { - - @Rule - public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); - - @Test - public void commentsViewTest() { - ViewInteraction appCompatButton = onView( - allOf(withId(R.id.feedButton), withText("Feed de Atividades"), - childAtPosition( - childAtPosition( - withId(android.R.id.content), - 0), - 2), - isDisplayed())); - appCompatButton.perform(click()); - - // Added a sleep statement to match the app's execution delay. - // The recommended way to handle such scenarios is to use Espresso idling resources: - // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html - try { - Thread.sleep(700); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - ViewInteraction appCompatTextView = onView( - allOf(withId(R.id.comments), withText("4 comentários"), - childAtPosition( - allOf(withId(R.id.feedActivity), - childAtPosition( - withId(R.id.feedRecyclerView), - 0)), - 11), - isDisplayed())); - appCompatTextView.perform(click()); - - // Added a sleep statement to match the app's execution delay. - // The recommended way to handle such scenarios is to use Espresso idling resources: - // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html - try { - Thread.sleep(700); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - ViewInteraction appCompatButton2 = onView( - allOf(withId(R.id.reportButton), withText("Denunciar"), - childAtPosition( - allOf(withId(R.id.commentsActivity), - childAtPosition( - withId(R.id.commentsRecyclerView), - 0)), - 2), - isDisplayed())); - appCompatButton2.perform(click()); - - ViewInteraction appCompatButton3 = onView( - allOf(withId(android.R.id.button1), withText("Sim"), - childAtPosition( - childAtPosition( - withClassName(is("android.widget.ScrollView")), - 0), - 3))); - appCompatButton3.perform(scrollTo(), click()); - - ViewInteraction appCompatButton4 = onView( - allOf(withId(android.R.id.button1), withText("Ok"), - childAtPosition( - childAtPosition( - withClassName(is("android.widget.ScrollView")), - 0), - 3))); - appCompatButton4.perform(scrollTo(), click()); - - ViewInteraction appCompatButton5 = onView( - allOf(withId(R.id.reportButton), withText("Denunciar"), - childAtPosition( - allOf(withId(R.id.commentsActivity), - childAtPosition( - withId(R.id.commentsRecyclerView), - 0)), - 2), - isDisplayed())); - appCompatButton5.perform(click()); - - ViewInteraction appCompatButton6 = onView( - allOf(withId(android.R.id.button2), withText("Não"), - childAtPosition( - childAtPosition( - withClassName(is("android.widget.ScrollView")), - 0), - 2))); - appCompatButton6.perform(scrollTo(), click()); - - } - - private static Matcher childAtPosition( - final Matcher parentMatcher, final int position) { - - return new TypeSafeMatcher() { - @Override - public void describeTo(Description description) { - description.appendText("Child at position " + position + " in parent "); - parentMatcher.describeTo(description); - } - - @Override - public boolean matchesSafely(View view) { - ViewParent parent = view.getParent(); - return parent instanceof ViewGroup && parentMatcher.matches(parent) - && view.equals(((ViewGroup) parent).getChildAt(position)); - } - }; - } -} diff --git a/project/app/src/main/AndroidManifest.xml b/project/app/src/main/AndroidManifest.xml index 71f9f6e5..58294c20 100644 --- a/project/app/src/main/AndroidManifest.xml +++ b/project/app/src/main/AndroidManifest.xml @@ -68,7 +68,7 @@ android:screenOrientation="portrait" android:windowSoftInputMode="adjustResize"/> @@ -116,14 +136,14 @@ class CommentsView: AppCompatActivity(), CommentsDisplayLogic { } override fun displayCommentsAfterDel(viewModel: CommentsModel.DeleteCommentRequest.ViewModel) { - (commentsRecyclerView.adapter as CommentsAdapter).deleteComment(viewModel.delCommentsFormatted) + (commentsRecyclerView?.adapter as CommentsAdapter).deleteComment(viewModel.delCommentsFormatted) } - private fun setActionToCloseKeyboard(view: View) { + private fun setActionToCloseKeyboard(view: View?) { // Set up touch listener for non-text box views to hide keyboard. if (view !is EditText) { - view.setOnTouchListener { _, _ -> //This '_' replaces the unused arguments + view?.setOnTouchListener { _, _ -> //This '_' replaces the unused arguments hideSoftKeyboard() false } @@ -139,25 +159,25 @@ class CommentsView: AppCompatActivity(), CommentsDisplayLogic { } private fun hideSoftKeyboard() { - val inputMethodManager = this.getSystemService( + val inputMethodManager = this.activity.getSystemService( Activity.INPUT_METHOD_SERVICE) as InputMethodManager inputMethodManager.hideSoftInputFromWindow( - this.currentFocus!!.windowToken, 0) + this.activity?.currentFocus?.windowToken, 0) } private fun rollToEndOfList(){ - commentsRecyclerView.smoothScrollToPosition( - commentsRecyclerView.adapter.itemCount-1 + commentsRecyclerView?.smoothScrollToPosition( + commentsRecyclerView?.adapter!!.itemCount-1 ) } private val sendCommentAction = View.OnClickListener { - if(commentEditText.text.isNotEmpty()){ + if(commentEditText?.text!!.isNotEmpty()){ val request = CommentsModel.PublishCommentRequest.Request( - commentEditText.text.toString() + commentEditText?.text.toString() ) interactor?.publishNewComment(request) - commentEditText.text.clear() + commentEditText?.text?.clear() rollToEndOfList() } } @@ -166,36 +186,36 @@ class CommentsView: AppCompatActivity(), CommentsDisplayLogic { * Adapter Class to control recycler view on ListLike * * @property comments It's a list of all comments - * @property context Context that will show this adapter + * @property fragment Context that will show this adapter */ class CommentsAdapter(var comments: MutableList, - private val context: Context) : RecyclerView.Adapter() { + private val fragment: Fragment) : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): - CommentsView.CommentsAdapter.ViewHolder { + CommentsFragment.CommentsAdapter.ViewHolder { - val view = LayoutInflater.from(context).inflate(R.layout.row_comments, + val view = LayoutInflater.from(fragment.activity).inflate(R.layout.row_comments, parent, false) view.setOnClickListener { - (context as CommentsView).hideSoftKeyboard() + (fragment as CommentsFragment).hideSoftKeyboard() } - return CommentsView.CommentsAdapter.ViewHolder(view) + return CommentsFragment.CommentsAdapter.ViewHolder(view) } - override fun onBindViewHolder(holder: CommentsView.CommentsAdapter.ViewHolder, + override fun onBindViewHolder(holder: CommentsFragment.CommentsAdapter.ViewHolder, position: Int) { holder.bindView(comments[position]) val message = String.format("Tem certeza que deseja denunciar o usuário " + "%s pela mensagem \"%s\"?", comments[position].username, comments[position].comment) holder.itemView.reportButton.setOnClickListener { - val builder = AlertDialog.Builder(context) + val builder = AlertDialog.Builder(fragment.activity) builder.setCancelable(true) builder.setMessage(message) builder.setPositiveButton("Sim", { dialogInterface, _ -> val request = CommentsModel.ComplaintRequest.Request(position) - (context as CommentsView).interactor?.sendComplaint(request) + (fragment as CommentsFragment).interactor?.sendComplaint(request) dialogInterface.dismiss() }) builder.setNegativeButton("Não", { dialogInterface, _ -> @@ -208,12 +228,12 @@ class CommentsView: AppCompatActivity(), CommentsDisplayLogic { val messageDel = "Tem certeza que deseja excluir esse comentário?" holder.itemView.deleteButton.setOnClickListener { - val builder = AlertDialog.Builder(context) + val builder = AlertDialog.Builder(fragment.activity) builder.setCancelable(true) builder.setMessage(messageDel) builder.setPositiveButton("Sim", { dialogInterface, _ -> val request = CommentsModel.DeleteCommentRequest.Request(position) - (context as CommentsView).interactor?.deleteComment(request) + (fragment as CommentsFragment).interactor?.deleteComment(request) dialogInterface.dismiss() }) builder.setNegativeButton("Não", { dialogInterface, _ -> diff --git a/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsInteractor.kt b/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsInteractor.kt index 9cfba0c7..553c0744 100644 --- a/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsInteractor.kt +++ b/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsInteractor.kt @@ -45,31 +45,41 @@ interface CommentsBusinessLogic { * @property worker Reference to Worker [CommentsWorker] * @property presenter Reference to Presenter [CommentsPresenter] */ -class CommentsInteractor(var presenter : CommentsPresentationLogic? = null) : CommentsBusinessLogic { + +class CommentsInteractor(var presenter : CommentsPresentationLogic? = null) : + CommentsBusinessLogic, CommentsWorkerUpdateLogic { var worker = CommentsWorker() override fun recentComments(request: CommentsModel.GetCommentsRequest.Request) { - worker.getCommentsData(request) { response -> - this.presenter?.presentComment(response) - } + worker.getCommentsData(request) } override fun publishNewComment(request: CommentsModel.PublishCommentRequest.Request) { - worker.setNewComment(request) { response -> - this.presenter?.presentNewComment(response) - } + worker.setNewComment(request) } override fun sendComplaint(request: CommentsModel.ComplaintRequest.Request) { - worker.sendComplaint(request) { response -> - this.presenter?.presentComplaint(response) - } + worker.sendComplaint(request) } override fun deleteComment(request: CommentsModel.DeleteCommentRequest.Request) { - worker.getToDeleteComment(request) { response -> - this.presenter?.presentPositionToDelete(response) - } + worker.getToDeleteComment(request) + } + + override fun updateComment(response: CommentsModel.GetCommentsRequest.Response) { + presenter?.presentComment(response) + } + + override fun updateDeleteComment(response: CommentsModel.DeleteCommentRequest.Response) { + presenter?.presentPositionToDelete(response) + } + + override fun updateNewComment(response: CommentsModel.PublishCommentRequest.Response) { + presenter?.presentNewComment(response) + } + + override fun updateSendComplaint(response: CommentsModel.ComplaintRequest.Response) { + presenter?.presentComplaint(response) } } \ No newline at end of file diff --git a/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsModel.kt b/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsModel.kt index 5b638864..1140104e 100644 --- a/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsModel.kt +++ b/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsModel.kt @@ -1,6 +1,6 @@ package com.nexte.nexte.CommentsScene -import java.util.* +import com.nexte.nexte.Entities.Comment.Comment /** * Class to define Model of Comments Scene to enable the conversation between users. @@ -110,7 +110,7 @@ class CommentsModel { * * @param delComments list of unformatted comments without deleted comment */ - class Response (var delComments: MutableList) + class Response (var delComments: Comment) /** * Class responsible to define the standar format of the information that will @@ -137,10 +137,6 @@ class CommentsModel { * @param author contains the player that posted the comment * @param commentId contains the comment identifier */ - class Comment(var comment: String, - var date: Date, - var author: Player, - var commentId: Int) /** * Class with formatted information about users and how they will be displayed in View diff --git a/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsPresenter.kt b/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsPresenter.kt index b6acd892..a8c5f4e7 100644 --- a/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsPresenter.kt +++ b/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsPresenter.kt @@ -1,6 +1,9 @@ package com.nexte.nexte.CommentsScene +import com.nexte.nexte.Entities.Comment.Comment +import com.nexte.nexte.Entities.User.UserManager +import com.nexte.nexte.R import java.text.SimpleDateFormat @@ -47,6 +50,7 @@ interface CommentsPresentationLogic { */ class CommentsPresenter : CommentsPresentationLogic { + var userManager: UserManager? = null var viewController: CommentsDisplayLogic? = null override fun presentComment(response: CommentsModel.GetCommentsRequest.Response) { @@ -65,12 +69,13 @@ class CommentsPresenter : CommentsPresentationLogic { val dateToShow = SimpleDateFormat("EEE, dd 'of' LLL") val time = dateToShow.format(newComment.date) + val userComment = userManager?.get(newComment.userId!!) val formatted = CommentsModel.CommentFormatted( - newComment.comment, + newComment.comment!!, time, - newComment.author.name, - newComment.author.photo + userComment!!.name, + R.mipmap.ic_launcher ) val viewModel = CommentsModel.PublishCommentRequest.ViewModel(formatted) @@ -104,7 +109,7 @@ class CommentsPresenter : CommentsPresentationLogic { */ override fun presentPositionToDelete(response: CommentsModel.DeleteCommentRequest.Response) { - val viewModel = CommentsModel.DeleteCommentRequest.ViewModel(formatComment(response.delComments)) + val viewModel = CommentsModel.DeleteCommentRequest.ViewModel(formatComment(mutableListOf(response.delComments))) viewController?.displayCommentsAfterDel(viewModel) } @@ -115,21 +120,21 @@ class CommentsPresenter : CommentsPresentationLogic { * @param gameComments MutableList of unformatted comments * @return MutableList of formatted comments */ - private fun formatComment(gameComments: MutableList) : + private fun formatComment(gameComments: MutableList) : MutableList { val commentsFormatted: MutableList = mutableListOf() for (gameComment in gameComments) { - + val user = userManager?.get(gameComment.userId!!) val dateToShow = SimpleDateFormat("EEE, dd 'of' LLL") val time = dateToShow.format(gameComment.date) val commentFormatted = CommentsModel.CommentFormatted( - gameComment.comment, + gameComment.comment!!, time, - gameComment.author.name, - gameComment.author.photo) + user!!.name, + R.mipmap.ic_launcher) commentsFormatted.add(commentFormatted) } diff --git a/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsWorker.kt b/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsWorker.kt index e8ceef15..c0e62e5f 100644 --- a/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsWorker.kt +++ b/project/app/src/main/java/com/nexte/nexte/CommentsScene/CommentsWorker.kt @@ -1,19 +1,29 @@ package com.nexte.nexte.CommentsScene -import com.nexte.nexte.R -import com.nexte.nexte.UserSingleton +import com.nexte.nexte.CommentsScene.CommentsModel.GetCommentsRequest.Response +import com.nexte.nexte.Entities.Comment.Comment +import com.nexte.nexte.Entities.Comment.CommentManager import java.util.* +interface CommentsWorkerUpdateLogic { + + fun updateComment(response: CommentsModel.GetCommentsRequest.Response) + fun updateNewComment(response: CommentsModel.PublishCommentRequest.Response) + fun updateDeleteComment(response: CommentsModel.DeleteCommentRequest.Response) + fun updateSendComplaint(response: CommentsModel.ComplaintRequest.Response) +} + /** * Class responsible to do request for anywhere, format Response and * call completion to send data for called class */ class CommentsWorker { + var updateLogic: CommentsWorkerUpdateLogic? = null + var commentsManager: CommentManager? = null /** * Variable created to simulate mocked data to be implemented on Package mocker */ - var commentsMockedData = generateCommentsList() /** * Function to get comments data of server @@ -21,11 +31,11 @@ class CommentsWorker { * @param request Comments model request that contains needed information to send to server * @param completion Method to call on parent class */ - fun getCommentsData (request: CommentsModel.GetCommentsRequest.Request, - completion: (CommentsModel.GetCommentsRequest.Response) -> Unit) { + fun getCommentsData (request: CommentsModel.GetCommentsRequest.Request) { - val response = CommentsModel.GetCommentsRequest.Response(this.generateCommentsList()) - completion(response) + val commentManager= commentsManager?.getAll() + val response = CommentsModel.GetCommentsRequest.Response(commentManager!!.toMutableList()) + updateLogic?.updateComment(response) } /** @@ -36,16 +46,16 @@ class CommentsWorker { * @param completion Method to call on parent class */ - fun setNewComment (request: CommentsModel.PublishCommentRequest.Request, - completion: (CommentsModel.PublishCommentRequest.Response) -> Unit) { + fun setNewComment (request: CommentsModel.PublishCommentRequest.Request) { + val message = request.commentToPost val today = Date() - val author = CommentsModel.Player(UserSingleton.getUserInformations().name, R.mipmap.ic_launcher) - val newComment = CommentsModel.Comment(message, today, author, 5) - this.commentsMockedData.add(newComment) + val author = "1" + var newComment = Comment(idComment, author, message, today) + newComment = commentsManager?.update(newComment)!! val response = CommentsModel.PublishCommentRequest.Response(newComment) - completion (response) + updateLogic?.updateNewComment(response) } /** @@ -56,14 +66,13 @@ class CommentsWorker { * @param completion Method to call on parent class */ - fun sendComplaint (request: CommentsModel.ComplaintRequest.Request, - completion: (CommentsModel.ComplaintRequest.Response) -> Unit) { + fun sendComplaint (request: CommentsModel.ComplaintRequest.Request) { val serverCode = okMessage - val response = CommentsModel.ComplaintRequest.Response(serverCode) - completion(response) + updateLogic?.updateSendComplaint(response) + } /** @@ -73,50 +82,15 @@ class CommentsWorker { * @param request Position of the comment to be deleted * @param completion List of unformatted list of comments after deletion */ - fun getToDeleteComment (request: CommentsModel.DeleteCommentRequest.Request, - completion: (CommentsModel.DeleteCommentRequest.Response) -> Unit){ + fun getToDeleteComment (request: CommentsModel.DeleteCommentRequest.Request){ - this.commentsMockedData.removeAt(request.commentIdentifier) - val response = CommentsModel.DeleteCommentRequest.Response(this.commentsMockedData) + val comments = this.commentsManager?.delete(request.commentIdentifier.toString()) + val response = CommentsModel.DeleteCommentRequest.Response(comments!!) - completion(response) + updateLogic?.updateDeleteComment(response) } - - /** - * Function to create fictional comments to use in fictional app mode - * - * @return MutableList of addComments - */ - private fun generateCommentsList(): MutableList { - - val player1 = CommentsModel.Player("Lorrany", R.mipmap.ic_launcher) - val player2 = CommentsModel.Player("Alexandre", R.mipmap.ic_launcher) - val player3 = CommentsModel.Player("Larissa", R.mipmap.ic_launcher) - val player4 = CommentsModel.Player("Letícia", R.mipmap.ic_launcher) - - val comment1 = CommentsModel.Comment("Nossa, esse jogo foi topzera", - Date(), - player1, 1) - val comment2 = CommentsModel.Comment("Boa galera, vocês arrasaram", - Date(), - player2, 2) - val comment3 = CommentsModel.Comment("Isso mesmo, man. Que jogão", - Date(), - player3, 3) - val comment4 = CommentsModel.Comment("Uhuuul, lindos!!", - Date(), - player4, 4) - - val addComments: MutableList = mutableListOf( - comment1, - comment2, - comment3, - comment4) - - return addComments - } - companion object { const val okMessage = 200 + const val idComment = "108" } } \ No newline at end of file diff --git a/project/app/src/main/java/com/nexte/nexte/FeedScene/FeedFragment.kt b/project/app/src/main/java/com/nexte/nexte/FeedScene/FeedFragment.kt index e8445274..88079b76 100644 --- a/project/app/src/main/java/com/nexte/nexte/FeedScene/FeedFragment.kt +++ b/project/app/src/main/java/com/nexte/nexte/FeedScene/FeedFragment.kt @@ -8,8 +8,8 @@ import android.support.v7.widget.RecyclerView import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import com.nexte.nexte.CommentsScene.CommentsFragment import com.nexte.nexte.LikeListScene.LikeListView -import com.nexte.nexte.CommentsScene.CommentsView import com.nexte.nexte.R import kotlinx.android.synthetic.main.row_feed.view.* @@ -44,7 +44,6 @@ class FeedFragment : Fragment(), FeedDisplayLogic { var feedViewAdapter: FeedAdapter? = null var feedRecyclerView : RecyclerView? = null - fun getInstance() : FeedFragment { return FeedFragment() } @@ -99,8 +98,12 @@ class FeedFragment : Fragment(), FeedDisplayLogic { private fun goToCommentsList() { - val intent = Intent(activity, CommentsView::class.java) - startActivity(intent) + val commentsFragment = CommentsFragment().getInstance() + val fragmentManager = activity.fragmentManager + val fragmentTransaction = fragmentManager.beginTransaction() + fragmentTransaction.replace(R.id.frame_layout, commentsFragment, "comments") + fragmentTransaction.addToBackStack(null) + fragmentTransaction.commit() } /** diff --git a/project/app/src/main/java/com/nexte/nexte/LoginScene/LoginModel.kt b/project/app/src/main/java/com/nexte/nexte/LoginScene/LoginModel.kt index 7dcbaeaa..9c0eb4b5 100644 --- a/project/app/src/main/java/com/nexte/nexte/LoginScene/LoginModel.kt +++ b/project/app/src/main/java/com/nexte/nexte/LoginScene/LoginModel.kt @@ -1,8 +1,5 @@ package com.nexte.nexte.LoginScene -import com.facebook.accountkit.AccountKitLoginResult - - /** * Class to define Model of Login Scene to send informations between layers */ @@ -52,9 +49,10 @@ class LoginModel { /** * Class responsible to store received information from Presenter to View - * @param loginResult: Result to a request for facebook API + * @param email: Email used to auth with facebook API + * @param phone: Phone used to auth with facebook API */ - class Request(val loginResult: AccountKitLoginResult) + class Request(val email: String?, val phone: String?) /** * Class responsible to store received information from worker to Presenter diff --git a/project/app/src/main/java/com/nexte/nexte/LoginScene/LoginView.kt b/project/app/src/main/java/com/nexte/nexte/LoginScene/LoginView.kt index 0e8d83fd..74b016af 100644 --- a/project/app/src/main/java/com/nexte/nexte/LoginScene/LoginView.kt +++ b/project/app/src/main/java/com/nexte/nexte/LoginScene/LoginView.kt @@ -3,14 +3,15 @@ package com.nexte.nexte.LoginScene import android.content.Intent import android.support.v7.app.AppCompatActivity import android.os.Bundle -import com.facebook.accountkit.AccountKitLoginResult -import com.facebook.accountkit.ui.AccountKitConfiguration -import com.facebook.accountkit.ui.AccountKitActivity -import com.facebook.accountkit.ui.LoginType import com.nexte.nexte.R import android.widget.Toast import android.util.Log +import com.facebook.accountkit.* import kotlinx.android.synthetic.main.activity_login_view.* +import com.facebook.accountkit.ui.AccountKitConfiguration +import com.facebook.accountkit.ui.AccountKitActivity +import com.facebook.accountkit.ui.LoginType + /** * Interface to define Display Logic to LoginView Class that will receive information @@ -49,6 +50,7 @@ class LoginView : AppCompatActivity(), LoginDisplayLogic { */ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + AccountKit.initialize(this) setContentView(R.layout.activity_login_view) this.setup() @@ -77,17 +79,14 @@ class LoginView : AppCompatActivity(), LoginDisplayLogic { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { - LoginModel.AccountKit.accountKit_code -> { - val loginResult = data?.getParcelableExtra(AccountKitLoginResult.RESULT_KEY) - val request: LoginModel.AccountKit.Request = LoginModel.AccountKit.Request(loginResult!!) - this.interactor?.accountKitAuthentication(request) + LoginModel.AccountKit.ACCOUNTKIT_CODE -> { + this.getAccount() } } } override fun displayAuthenticateState(viewModel: LoginModel.Authentication.ViewModel) { val message: String = viewModel.message - Log.i("wed", "dssdsd") val toast = Toast.makeText(this, message, Toast.LENGTH_SHORT) toast.show() } @@ -110,16 +109,25 @@ class LoginView : AppCompatActivity(), LoginDisplayLogic { } /** - * Method responsible for setup protocol between scenes + * Gets current account from Facebook Account Kit which include user's phone number */ - fun setup() { - val view = this - val interactor = LoginInteractor() - val presenter = LoginPresenter() + private fun getAccount() { + AccountKit.getCurrentAccount(object : AccountKitCallback { + override fun onSuccess(account: Account) { + val phoneNumber = account.getPhoneNumber() + val phoneNumberString = phoneNumber.toString() + + if(phoneNumberString != "") { + Log.i("Phone number:", phoneNumberString) + val request = LoginModel.AccountKit.Request("", phoneNumberString) + interactor?.accountKitAuthentication(request) + } + } - view.interactor = interactor - interactor.presenter = presenter - presenter.view = view + override fun onError(error: AccountKitError) { + Log.e("AccountKit", error.toString()) + } + }) } /** @@ -143,4 +151,17 @@ class LoginView : AppCompatActivity(), LoginDisplayLogic { intent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION, builder.build()) startActivityForResult(intent, LoginModel.AccountKit.accountKit_code) } + + /** + * Method responsible for setup protocol between scenes + */ + fun setup() { + val view = this + val interactor = LoginInteractor() + val presenter = LoginPresenter() + + view.interactor = interactor + interactor.presenter = presenter + presenter.view = view + } } diff --git a/project/app/src/main/java/com/nexte/nexte/LoginScene/LoginWorker.kt b/project/app/src/main/java/com/nexte/nexte/LoginScene/LoginWorker.kt index bdd8e56e..9e416642 100644 --- a/project/app/src/main/java/com/nexte/nexte/LoginScene/LoginWorker.kt +++ b/project/app/src/main/java/com/nexte/nexte/LoginScene/LoginWorker.kt @@ -3,6 +3,7 @@ package com.nexte.nexte.LoginScene import com.github.kittinunf.fuel.Fuel import com.github.kittinunf.result.failure import com.github.kittinunf.result.success +import com.nexte.nexte.UserSingleton import org.json.JSONObject /** @@ -22,7 +23,7 @@ class LoginWorker { fun authenticateUser(request: LoginModel.Authentication.Request, completion: (LoginModel.Authentication.Response) -> Unit) { - val authentication = "http://192.168.100.2:3000/auth/login" // Works only with IP + val authentication = "http://192.168.100.7:3000/auth/login" // Local route for auth val headers = mapOf("Content-Type" to "application/json", "Accept-Version" to "1.0.0") val json = JSONObject() @@ -35,6 +36,11 @@ class LoginWorker { val token = "1820uf09183h9d12db092ed9has9d1j020hf90aasfjialuch" val status = LoginModel.Authentication.StatusCode.AUTHORIZED val response = LoginModel.Authentication.Response(token, status) + + // TO DO: Add more user to server to authenticate with + val player = UserSingleton.getUserInformations() + UserSingleton.setUserInformations(player) + completion(response) } @@ -57,18 +63,48 @@ class LoginWorker { fun requestForAuth(request: LoginModel.AccountKit.Request, completion: (LoginModel.AccountKit.Response) -> Unit) { - val loginResult = request.loginResult - var response: LoginModel.AccountKit.Response? = null + val authentication = "http://192.168.100.7:3000/auth/login" // Local route for auth + val headers = mapOf("Content-Type" to "application/json", + "Accept-Version" to "1.0.0") + val body = defineBodyForAccountKitAuth(request.phone, request.email) + + Fuel.post(authentication).header(headers).body(body).responseString { request, response, result -> + + result.success { + + // TO DO: Add auth with token in NEXTE main server + val player = UserSingleton.getUserInformations() + UserSingleton.setUserInformations(player) + + val response = LoginModel.AccountKit.Response(LoginModel.AccountKit.StatusCode.SUCESSED) + completion(response) + } + + result.failure { + val response = LoginModel.AccountKit.Response(LoginModel.AccountKit.StatusCode.ERROR) + completion(response) + } + } + } - if (loginResult.wasCancelled()) { - response = LoginModel.AccountKit.Response(LoginModel.AccountKit.StatusCode.CANCELLED) - } else if (loginResult.error != null) { - response = LoginModel.AccountKit.Response(LoginModel.AccountKit.StatusCode.ERROR) - } else { - response = LoginModel.AccountKit.Response(LoginModel.AccountKit.StatusCode.SUCESSED) - } + /** + * Define body to authenticate user with Nexte main server + * @param phone Phone from a user - used in Account Kit auth + * @param phone Email from a user - used in Account Kit auth + */ + private fun defineBodyForAccountKitAuth(phone: String?, email: String?): String { + val json = JSONObject() + + if(phone != null) { + json.put("phone", phone) // Expected test-nexte-ramires + json.put("password", "test-nexte-ramires") // Expected ramires + + } else { + json.put("email", email) + json.put("password", "test-nexte-ramires") // Expected ramires + } - completion(response) + return json.toString() } } diff --git a/project/app/src/main/java/com/nexte/nexte/MainActivity.kt b/project/app/src/main/java/com/nexte/nexte/MainActivity.kt index afe3f9a4..c24f7546 100644 --- a/project/app/src/main/java/com/nexte/nexte/MainActivity.kt +++ b/project/app/src/main/java/com/nexte/nexte/MainActivity.kt @@ -35,13 +35,11 @@ class MainActivity : AppCompatActivity() { } private val mOnNavigationItemReselectedListener = BottomNavigationView.OnNavigationItemReselectedListener { item -> - when(item.itemId) { R.id.profile -> { /* Do Nothing*/ } } - } private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item -> @@ -73,9 +71,8 @@ class MainActivity : AppCompatActivity() { return@OnNavigationItemSelectedListener true } } - - } + private fun openFragment(fragment: Fragment) { val transaction = supportFragmentManager.beginTransaction() transaction.replace(R.id.frame_layout,fragment) diff --git a/project/app/src/main/res/drawable/check_comments_background.xml b/project/app/src/main/res/drawable/check_comments_background.xml new file mode 100644 index 00000000..01f0af0a --- /dev/null +++ b/project/app/src/main/res/drawable/check_comments_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/project/app/src/main/res/layout/activity_challenger.xml b/project/app/src/main/res/layout/activity_challenger.xml index 56be4ad1..5d0effca 100644 --- a/project/app/src/main/res/layout/activity_challenger.xml +++ b/project/app/src/main/res/layout/activity_challenger.xml @@ -37,8 +37,8 @@ android:text="@string/recebidos" /> - diff --git a/project/app/src/main/res/layout/activity_comments.xml b/project/app/src/main/res/layout/activity_comments.xml index c038b69f..52ea0213 100644 --- a/project/app/src/main/res/layout/activity_comments.xml +++ b/project/app/src/main/res/layout/activity_comments.xml @@ -5,44 +5,76 @@ android:id="@+id/mainLayout" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="#2E2E2E" - tools:context=".CommentsScene.CommentsView" - android:configChanges="keyboard|keyboardHidden"> + android:background="#393939" + android:configChanges="keyboard|keyboardHidden" + tools:context=".CommentsScene.CommentsFragment"> -