Skip to content

Commit

Permalink
Pre-release apk only
Browse files Browse the repository at this point in the history
  • Loading branch information
Shizen39 committed Jul 19, 2018
1 parent ef862c3 commit be5e23b
Show file tree
Hide file tree
Showing 19 changed files with 410 additions and 528 deletions.
7 changes: 4 additions & 3 deletions GeoNews/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
</activity>
<activity
android:name=".Activities.ArticleDetail.ArticleDetailActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/Theme.AppCompat.Light"
android:windowSoftInputMode="adjustResize">
<meta-data
Expand All @@ -36,6 +37,7 @@
</activity>
<activity
android:name=".Activities.ListArticles.ListArticlesActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/Theme.AppCompat.Light"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTop"> <!-- Otherwise system always creates a new instance of the activity in the target task -->
Expand All @@ -58,6 +60,7 @@

<activity
android:name=".Activities.MapActivity.MapsActivity"
android:configChanges="orientation|screenSize"
android:label="@string/title_activity_maps"
android:windowSoftInputMode="adjustResize">
<intent-filter>
Expand All @@ -67,9 +70,7 @@
android:resource="@xml/searchable"
android:value="com.example.giorgio.geonews.Activities.Main.MainActivity" />
</activity>
<activity android:name=".Activities.MapActivity.DayNightCycleActivity" />
<activity android:name=".Activities.MapActivity.BasicGlobeActivity" />
<activity android:name=".Activities.MapActivity.AbstractMainActivity"></activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.giorgio.geonews.Activities.ArticleDetail
import android.app.Fragment
import android.content.Context
import android.os.Bundle
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
Expand All @@ -14,93 +15,93 @@ import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import com.example.giorgio.geonews.Data_utils.DB.Constant
import com.example.giorgio.geonews.Data_utils.DB.getAndroidID
import com.example.giorgio.geonews.Data_utils.DB.getColor
import com.example.giorgio.geonews.Data_utils.UsrComment
import com.example.giorgio.geonews.Networking.CheckNetworking
import com.example.giorgio.geonews.Networking.CreateComment
import com.example.giorgio.geonews.Networking.RetrieveUsrID
import com.example.giorgio.geonews.Networking.UpdateComment
import com.example.giorgio.geonews.Networking.*
import com.example.giorgio.geonews.R
import kotlinx.android.synthetic.main.row_comments.*




/**
* Created by giorgio on 03/07/18.
* Fragment attached to ArticleDetailActivity that show latest user comments in a RV, calling fetchComments and using CommentsUtils and UserUtils
* -> Networking.fetchComments()
* -> CommentsUtils.CreateComment() / .UpdateComment() / .DeleteComment() / .RetrieveUsrID()
* (*) this -> fetchComments.onResponse() -> RV_Adapter.RecyclerViewAdapter
* GeoNews
*/

class ArticleCommentFragment : Fragment(), View.OnClickListener {

/**
* Init variables
*/
lateinit var commentInput: EditText //Edit text for input comment
lateinit var my_img: TextView
lateinit var c: Constant
lateinit var android_id: String
lateinit var articleUrl: String
var updating= false
lateinit var oldItem: UsrComment
/** Init variables */
lateinit var commentInput: EditText // Edit text for input comment
lateinit var my_img: TextView // ImgView for user image id near commentInput
lateinit var android_id: String // User android HW id
lateinit var articleUrl: String // url of selected article
var updating= false // boolean that check if a user is typing in commentInput because it's updating or creating a new comment
lateinit var oldItem: UsrComment // old comment for query purpose, in case user has updated the comment

/** OnCreateView func */
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_comments, container, false)

val sendButton: Button = view.findViewById(R.id.send_comment) //init send button
commentInput= view.findViewById(R.id.insert_comment) //find edittext
my_img= view.findViewById(R.id.my_image)
//init helpers
c= Constant()
android_id= getAndroidID(this.context).toString()
val view = inflater.inflate(R.layout.fragment_comments, container, false) // inflate fragment
val sendButton: Button = view.findViewById(R.id.send_comment) // init send comment button
commentInput= view.findViewById(R.id.insert_comment) // find editText
my_img= view.findViewById(R.id.my_image) // find usr image
android_id= getAndroidID(this.context).toString() // get android HW id (-> UsrUtils)

//Edittext break the fullscreen ui. Some adjustment
/* Edittext break the fullscreen ui. Some adjustment */
commentInput.setOnClickListener({activity.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)})
commentInput.onFocusChangeListener = View.OnFocusChangeListener { v, hasFocus -> if (hasFocus) activity.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)}

sendButton.setOnClickListener(this)//set send button for sending comments
sendButton.setOnClickListener(this) // set send comment button listener for sending comments
return view

}


/** Called after onCreateView */
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
//Find RV of comments
/* Find comments RV */
val mRecyclerView = view?.findViewById(R.id.RV_comments) as RecyclerView
val mLayoutManager = LinearLayoutManager(this.context)
//mLayoutManager.stackFromEnd = true //in order to visualize always the lates comments
mRecyclerView.layoutManager = mLayoutManager
}

/* Sets up a SwipeRefreshLayout.OnRefreshListener invoked when the user performs a swipe-to-refresh gesture. */
val mSwipeRefreshLayout = view.findViewById(R.id.swiperefreshComment) as SwipeRefreshLayout
mSwipeRefreshLayout.setOnRefreshListener({
Commenting.fetchComments(this.context, articleUrl) // (*) this -> fetchComments.onResponse() -> RV_Adapter.RecyclerViewAdapter
mSwipeRefreshLayout.isRefreshing = false
})
}

/**
* On button send click, do postComment() and hide keyboard
* -> onCreateView.sendButton.
* On button send comment click, do postComment() and hide keyboard
*/
override fun onClick(v: View?) {
ArticleDetailActivity().hideSystemUI(activity.window.decorView, false)
if(!updating) { //User start tiping new comment
if (!commentInput.text.isBlank()) { //If user has written something
if (CheckNetworking.isNetworkAvailable(this.context)) { //post the comment if there's interne connection
val usrId = getUsrID() //get user id by it's android_id + article url
my_img.text = usrId //set personal userId near of edittext
CreateComment.post(context, commentInput.text.toString(), articleUrl, android_id, usrId) //make a post request
if(!updating) { // User start typing a new comment (not already existing)
if (!commentInput.text.isBlank()) { // If user has written something in editText, crate comment (else do nothing)
if (CheckNetworking.isNetworkAvailable(this.context)) {
val usrId = getUsrID() // get comments user id by fetching on DB ->
my_img.text = usrId
CreateComment.createComment(context, commentInput.text.toString(),
articleUrl, android_id, usrId) //make a createComment request
} else Toast.makeText(this.context, "No internet connection. Please check and try again.", Toast.LENGTH_LONG).show()
}
}
else { //User is updating his comment
else { // User is updating his comment
println(commentInput.text.toString())
println(oldItem)
if (commentInput.text.toString() != oldItem.comment) { //If user has updated the comment
if (CheckNetworking.isNetworkAvailable(this.context)) //post the comment if there's interne connection
UpdateComment.updateComment(this.context, commentInput.text.toString(), oldItem.id, articleUrl)
if (commentInput.text.toString() != oldItem.comment) { // If user has updated the comment in editText, crate comment (else do nothing)
if (CheckNetworking.isNetworkAvailable(this.context))
UpdateComment.updateComment(this.context, commentInput.text.toString(),
oldItem.id, articleUrl)
else Toast.makeText(this.context, "No internet connection. Please check and try again.", Toast.LENGTH_LONG).show()
}
updating=false
updating=false // updated. Change state
}
commentInput.text.clear() //clear edit text input
//Hide keyboard after send comment
commentInput.text.clear() // clear edit text input
/* Hide keyboard after send comment */
val editV= this.activity.currentFocus
if(editV!=null){
val inputManager = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
Expand All @@ -111,27 +112,27 @@ class ArticleCommentFragment : Fragment(), View.OnClickListener {


/**
* Get user id by it's android_id + article url
* --> onClick.usrId =
* Get comments user id by it's android_id + article url
*/
private fun getUsrID() : String {
//set background color
/* set user image background color */
val backgroundColor=getColor(android_id, articleUrl)
user_image.background.setTint(backgroundColor) //for
my_img.background.setTint(backgroundColor)


//get and set user id
/* get and set comments user id */
var result= RetrieveUsrID.MakeNetworkRequestAsyncTask().execute(articleUrl, android_id).get()

return if(result != "") //Usr has already written
return if(result != "") // Usr has already written another comment
result
else{ //Usr has not already written, get last Usr and add 1
else{ // Usr has not already written
result=RetrieveUsrID.MakeNetworkRequestAsyncTask().execute(articleUrl, null).get()

if(result != ""){ //another usr has already written
if(result != ""){ // Another usr has already written -> get last Usr id + 1
(result.toInt()+1).toString()
}
else{//usr comment is first comment
else{ // usr comment is first comment -> get 1
"1"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@ import kotlinx.android.synthetic.main.activity_detail_webview.*


/**
* Activity that show the opened article with a webview
* Created by giorgio on 02/07/18.
* Activity that shows the selected article with a webView
* ArticleDetailActivity -> ArticleCommentFragment
* ArticleDetailActivity -> Commenting.fetchComments (articleUrl)
* GeoNews
*/


class ArticleDetailActivity : AppCompatActivity() {

//fBack button on actionBar... For webview, in order to go back in history
/** change fBack button on actionBar behavior; For webview, in order to go back in history */
override fun onBackPressed() {
if (WV_article_detail.canGoBack()) {
hideSystemUI(window.decorView,true)
WV_article_detail.goBack()
} else {

// Otherwise defer to system default behavior.
} else { // Otherwise defer to system default behavior.
hideSystemUI(window.decorView,true)
super.onBackPressed()

}
}

//Function to handle UI behavior
fun hideSystemUI(decorView: View, hasFocus: Boolean) {
if (hasFocus) decorView.systemUiVisibility= (
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
Expand All @@ -49,18 +51,15 @@ class ArticleDetailActivity : AppCompatActivity() {
)
}

//OnCreate func
/** OnCreate func */
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
hideSystemUI(window.decorView,true)
setContentView(R.layout.activity_detail_webview)

WV_article_detail.webViewClient = WebViewClient() // prevent opening in default browser


//prevent opening in default browser
WV_article_detail.webViewClient = WebViewClient()

//add some settings for webpages
/* add some settings for webpages */
val settings= WV_article_detail.settings
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
settings.safeBrowsingEnabled = false
Expand All @@ -72,29 +71,22 @@ class ArticleDetailActivity : AppCompatActivity() {
settings.setAppCacheEnabled(true)
settings.setAppCachePath("")

//get url from intent of RV_Adapter
val articleUrl= intent.getStringExtra(CustomViewHolder.ARTICLE_LINK_KEY)

//load webview's url
if(CheckNetworking.isNetworkAvailable(this))
val articleUrl= intent.getStringExtra(CustomViewHolder.ARTICLE_LINK_KEY) // get url from intent of RV_Adapter
if(CheckNetworking.isNetworkAvailable(this)) // load webview's url
WV_article_detail.loadUrl(articleUrl)
else Toast.makeText(this, "No internet connection. Please check and try again.", Toast.LENGTH_LONG).show()

//set actionbar title
title= if (articleUrl.contains("http://")) articleUrl.removePrefix("http://") else articleUrl.removePrefix("https://")

//get fragment
/* Get comments fragment */
val ft = fragmentManager.beginTransaction()
val frag= fragmentManager.findFragmentById(R.id.F_comments) as (ArticleCommentFragment)

//pass url to comment fragment
frag.articleUrl=articleUrl
//and hide it
ft.hide(frag)
frag.articleUrl=articleUrl // pass Articleurl to comment fragment so it can use it
ft.hide(frag) // and hide it
ft.commit()

//Set the hide/show button for comments
addShowHideListener(R.id.F_Button, frag, articleUrl)
addShowHideListener(R.id.F_Button, frag, articleUrl) // Set the hide/show button for comments

}

Expand All @@ -105,23 +97,20 @@ class ArticleDetailActivity : AppCompatActivity() {
val button = findViewById<View>(buttonId) as FloatingActionButton
button.setOnClickListener {
val ft = fragmentManager.beginTransaction()
ft.setCustomAnimations(android.R.animator.fade_in,
android.R.animator.fade_out)
if (fragment.isHidden) {
ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out)
if (fragment.isHidden) { //show comments
if(CheckNetworking.isNetworkAvailable(this))
Commenting.fetchComments(this, articleUrl) //fetch new comments and VIEW them (in fetchComments.onResponse)
else Toast.makeText(this, "No internet connection. Please check and try again.", Toast.LENGTH_LONG).show()

ft.show(fragment) //show comments
hideSystemUI(window.decorView,false) //show navbar
ft.addToBackStack(null) //for navbar back button to hide fragment
} else {
ft.hide(fragment) //hide comments
Commenting.fetchComments(this, articleUrl) //fetch new comments and VIEW them (in fetchComments.onResponse)
else Toast.makeText(this, "No internet connection. " +
"Please check and try again.", Toast.LENGTH_LONG).show()
ft.show(fragment)
hideSystemUI(window.decorView,false) //show navbar
ft.addToBackStack(null) //for navbar back button to hide fragment
} else { //hide comments
ft.hide(fragment)
hideSystemUI(window.decorView,true) //hide navbar
}
ft.commit()
}
}


}
Loading

0 comments on commit be5e23b

Please sign in to comment.