|
@ -5,12 +5,17 @@ import android.view.LayoutInflater; |
|
|
import android.view.View; |
|
|
import android.view.View; |
|
|
import android.view.ViewGroup; |
|
|
import android.view.ViewGroup; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
import androidx.annotation.NonNull; |
|
|
import androidx.annotation.Nullable; |
|
|
import androidx.annotation.Nullable; |
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager; |
|
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.activities.main.forum.ForumFragment; |
|
|
|
|
|
import gr.thmmy.mthmmy.base.BaseFragment; |
|
|
import gr.thmmy.mthmmy.base.BaseFragment; |
|
|
|
|
|
import gr.thmmy.mthmmy.model.Shout; |
|
|
import gr.thmmy.mthmmy.utils.CustomRecyclerView; |
|
|
import gr.thmmy.mthmmy.utils.CustomRecyclerView; |
|
|
|
|
|
import gr.thmmy.mthmmy.utils.NetworkResultCodes; |
|
|
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; |
|
|
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; |
|
|
|
|
|
|
|
|
public class ShoutboxFragment extends BaseFragment { |
|
|
public class ShoutboxFragment extends BaseFragment { |
|
@ -18,9 +23,13 @@ public class ShoutboxFragment extends BaseFragment { |
|
|
private static final String TAG = "ShoutboxFragment"; |
|
|
private static final String TAG = "ShoutboxFragment"; |
|
|
|
|
|
|
|
|
private MaterialProgressBar progressBar; |
|
|
private MaterialProgressBar progressBar; |
|
|
|
|
|
private ShoutboxTask shoutboxTask; |
|
|
|
|
|
private ShoutAdapter shoutAdapter; |
|
|
|
|
|
private SwipeRefreshLayout swipeRefreshLayout; |
|
|
|
|
|
private ArrayList<Shout> shouts; |
|
|
|
|
|
|
|
|
public static ForumFragment newInstance(int sectionNumber) { |
|
|
public static ShoutboxFragment newInstance(int sectionNumber) { |
|
|
ForumFragment fragment = new ForumFragment(); |
|
|
ShoutboxFragment fragment = new ShoutboxFragment(); |
|
|
Bundle args = new Bundle(); |
|
|
Bundle args = new Bundle(); |
|
|
args.putString(ARG_TAG, TAG); |
|
|
args.putString(ARG_TAG, TAG); |
|
|
args.putInt(ARG_SECTION_NUMBER, sectionNumber); |
|
|
args.putInt(ARG_SECTION_NUMBER, sectionNumber); |
|
@ -28,6 +37,20 @@ public class ShoutboxFragment extends BaseFragment { |
|
|
return fragment; |
|
|
return fragment; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onShoutboxTaskSarted() { |
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onShoutboxTaskFinished(int resultCode, ArrayList<Shout> shouts) { |
|
|
|
|
|
progressBar.setVisibility(View.INVISIBLE); |
|
|
|
|
|
swipeRefreshLayout.setRefreshing(false); |
|
|
|
|
|
if (resultCode == NetworkResultCodes.SUCCESSFUL) { |
|
|
|
|
|
this.shouts.clear(); |
|
|
|
|
|
this.shouts.addAll(shouts); |
|
|
|
|
|
shoutAdapter.notifyDataSetChanged(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Nullable |
|
|
@Nullable |
|
|
@Override |
|
|
@Override |
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
|
@ -35,7 +58,20 @@ public class ShoutboxFragment extends BaseFragment { |
|
|
|
|
|
|
|
|
progressBar = rootView.findViewById(R.id.progressBar); |
|
|
progressBar = rootView.findViewById(R.id.progressBar); |
|
|
CustomRecyclerView recyclerView = rootView.findViewById(R.id.shoutbox_recyclerview); |
|
|
CustomRecyclerView recyclerView = rootView.findViewById(R.id.shoutbox_recyclerview); |
|
|
|
|
|
shouts = new ArrayList<>(); |
|
|
|
|
|
shoutAdapter = new ShoutAdapter(getContext(), shouts); |
|
|
|
|
|
recyclerView.setAdapter(shoutAdapter); |
|
|
|
|
|
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); |
|
|
|
|
|
shoutboxTask = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished); |
|
|
|
|
|
shoutboxTask.execute("https://www.thmmy.gr/smf/index.php?"); |
|
|
|
|
|
|
|
|
|
|
|
swipeRefreshLayout = rootView.findViewById(R.id.swiperefresh); |
|
|
|
|
|
swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.primary); |
|
|
|
|
|
swipeRefreshLayout.setOnRefreshListener(() -> { |
|
|
|
|
|
shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished); |
|
|
|
|
|
shoutboxTask.execute("https://www.thmmy.gr/smf/index.php?"); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
return super.onCreateView(inflater, container, savedInstanceState); |
|
|
return rootView; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|