1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
package com.example.brzodolokacije.Fragments
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import com.exam.DBHelper
import com.example.brzodolokacije.Activities.ActivityChangePassword
import com.example.brzodolokacije.Activities.ActivityChangeUserData
import com.example.brzodolokacije.Activities.ActivityLoginRegister
import com.example.brzodolokacije.FragmentProfileStatistics
import com.example.brzodolokacije.R
import com.example.brzodolokacije.Services.RetrofitHelper
import com.example.brzodolokacije.Services.SharedPreferencesHelper
class FragmentMyProfileInfo : Fragment() {
private lateinit var logout:Button
private lateinit var changeAccount:Button
private lateinit var statistics:Button
private lateinit var changePassword:Button
private lateinit var favouritePosts:Button
private lateinit var inviteFriends:Button
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
var view=inflater.inflate(R.layout.fragment_my_profile_info, container, false)
logout=view.findViewById<View>(R.id.buttonLogOut) as Button
changeAccount=view.findViewById(R.id.changeAccountData)
statistics=view.findViewById<View>(R.id.getAccoutStatistics) as Button
changePassword=view.findViewById(R.id.ChangePassword)
favouritePosts=view.findViewById(R.id.getMyFavorite)
inviteFriends=view.findViewById(R.id.inviteFriends)
logout.setOnClickListener{
logOut()
}
changeAccount.setOnClickListener {
val intent = Intent (getActivity(), ActivityChangeUserData::class.java)
getActivity()?.startActivity(intent)
}
inviteFriends.setOnClickListener {
val uri: Uri =
Uri.parse(RetrofitHelper.baseUrl+"/api/app/download") // missing 'http://' will cause crashed
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
}
favouritePosts.setOnClickListener {
val manager: androidx.fragment.app.FragmentManager? = fragmentManager
val transaction: FragmentTransaction = manager!!.beginTransaction()
var fragment:FragmentUserPosts=FragmentUserPosts()
val bundle = Bundle()
var parentFragment:FragmentProfile=parentFragment as FragmentProfile
var username=parentFragment.usernameStringSend
bundle.putString("username", username)
fragment.arguments=bundle
transaction.replace(R.id.flFragmentProfileFragmentContainer,fragment )
transaction.commit()
}
statistics.setOnClickListener {
val manager: androidx.fragment.app.FragmentManager? = fragmentManager
val transaction: FragmentTransaction = manager!!.beginTransaction()
var fragment:FragmentProfileStatistics=FragmentProfileStatistics()
val bundle = Bundle()
var parentFragment:FragmentProfile=parentFragment as FragmentProfile
var username=parentFragment.usernameStringSend
bundle.putString("username", username)
fragment.arguments=bundle
transaction.replace(R.id.flFragmentProfileFragmentContainer,fragment )
transaction.commit()
}
changePassword.setOnClickListener {
val intent = Intent (getActivity(), ActivityChangePassword::class.java)
getActivity()?.startActivity(intent)
}
return view
}
fun logOut(){
if(SharedPreferencesHelper.removeValue("jwt",requireActivity()))
{
DBHelper.getInstance(requireActivity()).deleteDB();
val intent= Intent(requireActivity(), ActivityLoginRegister::class.java)
startActivity(intent)
requireActivity().finish()
}
}
}
|